[CLEANUP] main_rte function of the ElementBrowser
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / Classes / SelectImage.php
index 640ee07..895c92a 100644 (file)
@@ -2,6 +2,22 @@
 namespace TYPO3\CMS\Rtehtmlarea;
 
 /**
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Resource;
+
+/**
  * Script Class
  *
  * @author     Kasper Skårhøj <kasper@typo3.com>
@@ -9,6 +25,13 @@ namespace TYPO3\CMS\Rtehtmlarea;
 class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
 
        /**
+        * These file extensions are allowed in the "plain" image selection mode.
+        *
+        * @const
+        */
+       const PLAIN_MODE_IMAGE_FILE_EXTENSIONS = 'jpg,jpeg,gif,png';
+
+       /**
         * @todo Define visibility
         */
        public $extKey = 'rtehtmlarea';
@@ -24,18 +47,22 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
 
        protected $defaultClass;
 
+       /**
+        * Relevant for RTE mode "plain": the maximum width an image must have to be selectable.
+        *
+        * @var int
+        */
        protected $plainMaxWidth;
 
+       /**
+        * Relevant for RTE mode "plain": the maximum height an image must have to be selectable.
+        *
+        * @var int
+        */
        protected $plainMaxHeight;
 
-       protected $magicMaxWidth;
-
-       protected $magicMaxHeight;
-
        protected $imgPath;
 
-       protected $RTEImageStorageDir;
-
        public $editorNo;
 
        public $sys_language_content;
@@ -46,99 +73,70 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
 
        protected $imgObj;
 
-       // Instance object of t3lib_stdGraphic
        /**
         * Initialisation
         *
-        * @return      void
-        * @todo Define visibility
+        * @return void
         */
        public function init() {
                $this->initVariables();
                $this->initConfiguration();
-               $this->initHookObjects();
-               // init fileProcessor
-               $this->fileProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
-               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
+               $this->initHookObjects('ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php');
+
                $this->allowedItems = $this->getAllowedItems('magic,plain,image');
                $this->insertImage();
-               // Creating backend template object:
-               $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
-               // Apply the same styles as those of the base script
-               $this->doc->bodyTagId = 'typo3-browse-links-php';
-               $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
-               $this->doc->backPath = $GLOBALS['BACK_PATH'];
-               // Load the Prototype library and browse_links.js
-               $this->doc->getPageRenderer()->loadPrototype();
-               $this->doc->loadJavascriptLib('js/tree.js');
-               $this->doc->loadJavascriptLib('js/browse_links.js');
-               $this->doc->JScode .= $this->doc->wrapScriptTags('
-                       Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
-               ');
-               $this->doc->getContextMenuCode();
+
+               $this->initDocumentTemplate();
        }
 
        /**
         * Initialize class variables
         *
-        * @return      void
+        * @return void
         */
        public function initVariables() {
+               parent::initVariables();
                // Get "act"
-               $this->act = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('act');
+               $this->act = GeneralUtility::_GP('act');
                if (!$this->act) {
                        $this->act = FALSE;
                }
                // Process bparams
-               $this->bparams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('bparams');
                $pArr = explode('|', $this->bparams);
                $pRteArr = explode(':', $pArr[1]);
                $this->editorNo = $pRteArr[0];
                $this->sys_language_content = $pRteArr[1];
                $this->RTEtsConfigParams = $pArr[2];
                if (!$this->editorNo) {
-                       $this->editorNo = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('editorNo');
-                       $this->sys_language_content = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('sys_language_content');
-                       $this->RTEtsConfigParams = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('RTEtsConfigParams');
+                       $this->editorNo = GeneralUtility::_GP('editorNo');
+                       $this->sys_language_content = GeneralUtility::_GP('sys_language_content');
+                       $this->RTEtsConfigParams = GeneralUtility::_GP('RTEtsConfigParams');
                }
-               $this->expandPage = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('expandPage');
-               $this->expandFolder = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('expandFolder');
                $pArr[1] = implode(':', array($this->editorNo, $this->sys_language_content));
                $pArr[2] = $this->RTEtsConfigParams;
                if ($this->act == 'dragdrop' || $this->act == 'plain') {
-                       $this->allowedFileTypes = explode(',', 'jpg,jpeg,gif,png');
+                       $this->allowedFileTypes = explode(',', self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS);
                }
                $pArr[3] = implode(',', $this->allowedFileTypes);
                $this->bparams = implode('|', $pArr);
-               // Find "mode"
-               $this->mode = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('mode');
-               if (!$this->mode) {
-                       $this->mode = 'rte';
-               }
-               // Site URL
-               $this->siteURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
-               // Current site url
-               // the script to link to
-               $this->thisScript = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('SCRIPT_NAME');
        }
 
        /**
-        * Initialize hook objects implementing interface t3lib_browseLinksHook
+        * Initialize document template object
         *
-        * @return      void
+        * @return void
         */
-       protected function initHookObjects() {
-               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'])) {
-                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'] as $classData) {
-                               $processObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj($classData);
-                               if (!$processObject instanceof \TYPO3\CMS\Core\ElementBrowser\ElementBrowserHookInterface) {
-                                       throw new \UnexpectedValueException('$processObject must implement interface TYPO3\\CMS\\Core\\ElementBrowser\\ElementBrowserHookInterface', 1195115652);
-                               }
-                               $parameters = array();
-                               $processObject->init($this, $parameters);
-                               $this->hookObjects[] = $processObject;
-                       }
-               }
+       protected function initDocumentTemplate() {
+               parent::initDocumentTemplate();
+
+               $this->doc->bodyTagId = 'typo3-browse-links-php';
+               $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
+
+               $this->doc->JScode .= $this->doc->wrapScriptTags('
+                       Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
+               ');
+               $this->doc->getPageRenderer()->addCssFile($this->doc->backPath . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('t3skin') . 'rtehtmlarea/htmlarea.css');
+               $this->doc->getContextMenuCode();
        }
 
        /**
@@ -153,10 +151,12 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        /**
         * Get the path to the folder where RTE images are stored
         *
-        * @return      string          the path to the folder where RTE images are stored
+        * @return  string the path to the folder where RTE images are stored
+        * @deprecated since 6.2, will be removed in two versions
         */
        protected function getRTEImageStorageDir() {
-               return $this->imgPath ? $this->imgPath : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];
+               GeneralUtility::logDeprecatedFunction();
+               return $this->imgPath ?: $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir'];
        }
 
        /**
@@ -165,30 +165,30 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
         * @return      void
         */
        protected function insertImage() {
-               if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('insertImage')) {
-                       $table = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('table');
-                       $uid = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('uid');
-                       $fileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileObject($uid);
+               $table = htmlspecialchars(GeneralUtility::_GP('table'));
+               $uid = (int) GeneralUtility::_GP('uid');
+               if (GeneralUtility::_GP('insertImage') && $uid) {
+                       /** @var $fileObject Resource\File */
+                       $fileObject = Resource\ResourceFactory::getInstance()->getFileObject($uid);
                        // Get default values for alt and title attributes from file properties
                        $altText = $fileObject->getProperty('alternative');
-                       $titleText = $fileObject->getProperty('name');
+                       $titleText = $fileObject->getProperty('title');
                        switch ($this->act) {
-                       case 'magic':
-                               $this->insertMagicImage($fileObject, $altText, $titleText, 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
-                               die;
-                               break;
-                       case 'plain':
-                               $this->insertPlainImage($fileObject, $altText, $titleText, 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
-                               die;
-                               break;
-                       default:
-                               // Call hook
-                               foreach ($this->hookObjects as $hookObject) {
-                                       if (method_exists($hookObject, 'insertElement')) {
-                                               $hookObject->insertElement($this->act);
+                               case 'magic':
+                                       $this->insertMagicImage($fileObject, $altText, $titleText, 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
+                                       die;
+                                       break;
+                               case 'plain':
+                                       $this->insertPlainImage($fileObject, $altText, $titleText, 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
+                                       die;
+                                       break;
+                               default:
+                                       // Call hook
+                                       foreach ($this->hookObjects as $hookObject) {
+                                               if (method_exists($hookObject, 'insertElement')) {
+                                                       $hookObject->insertElement($this->act);
+                                               }
                                        }
-                               }
-                               break;
                        }
                }
        }
@@ -196,49 +196,56 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        /**
         * Insert a magic image
         *
-        * @param \TYPO3\CMS\Core\Resource\FileInterface $fileObject: the image file
-        * @param       string          $altText: text for the alt attribute of the image
-        * @param       string          $titleText: text for the title attribute of the image
-        * @param       string          $additionalParams: text representing more HTML attributes to be added on the img tag
-        * @return      void
+        * @param Resource\File $fileObject: the image file
+        * @param string $altText: text for the alt attribute of the image
+        * @param string $titleText: text for the title attribute of the image
+        * @param string $additionalParams: text representing more HTML attributes to be added on the img tag
+        * @return void
         */
-       public function insertMagicImage(\TYPO3\CMS\Core\Resource\FileInterface $fileObject, $altText = '', $titleText = '', $additionalParams = '') {
-               if ($this->RTEImageStorageDir) {
-                       // Create the magic image
-                       /** @var $magicImageService \TYPO3\CMS\Core\Resource\Service\MagicImageService */
-                       $magicImageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService');
-                       $imageConfiguration = array(
-                               'width' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cWidth'),
-                               'height' => \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cHeight'),
-                               'maxW' => $this->magicMaxWidth,
-                               'maxH' => $this->magicMaxHeight
-                       );
-                       $magicImage = $magicImageService->createMagicImage($fileObject, $imageConfiguration, $this->getRTEImageStorageDir());
-                       if ($magicImage instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
-                               $filePath = $magicImage->getForLocalProcessing(FALSE);
-                               $imageInfo = @getimagesize($filePath);
-                               $imageUrl = $this->siteURL . substr($filePath, strlen(PATH_site));
-                               $this->imageInsertJS($imageUrl, $imageInfo[0], $imageInfo[1], $altText, $titleText, $additionalParams);
-                       }
-               } else {
-                       \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Attempt at creating a magic image failed due to absent RTE_imageStorageDir', $this->extKey . '/tx_rtehtmlarea_select_image', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
-               }
+       public function insertMagicImage(Resource\File $fileObject, $altText = '', $titleText = '', $additionalParams = '') {
+               // Create the magic image service
+               /** @var $magicImageService Resource\Service\MagicImageService */
+               $magicImageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Service\\MagicImageService');
+               $magicImageService->setMagicImageMaximumDimensions($this->thisConfig);
+               // Create the magic image
+               $imageConfiguration = array(
+                       'width' => GeneralUtility::_GP('cWidth'),
+                       'height' => GeneralUtility::_GP('cHeight')
+               );
+               $magicImage = $magicImageService->createMagicImage($fileObject, $imageConfiguration);
+               $imageUrl = $magicImage->getPublicUrl();
+               // If file is local, make the url absolute
+               if (substr($imageUrl, 0, 4) !== 'http') {
+                       $imageUrl = $this->siteURL . $imageUrl;
+               }
+               // Insert the magic image
+               $this->imageInsertJS($imageUrl, $magicImage->getProperty('width'), $magicImage->getProperty('height'), $altText, $titleText, $additionalParams);
        }
 
        /**
         * Insert a plain image
         *
-        * @param \TYPO3\CMS\Core\Resource\FileInterface $fileObject: the image file
+        * @param \TYPO3\CMS\Core\Resource\File $fileObject: the image file
         * @param       string          $altText: text for the alt attribute of the image
         * @param       string          $titleText: text for the title attribute of the image
         * @param       string          $additionalParams: text representing more HTML attributes to be added on the img tag
         * @return      void
         */
-       public function insertPlainImage(\TYPO3\CMS\Core\Resource\FileInterface $fileObject, $altText = '', $titleText = '', $additionalParams = '') {
-               $filePath = $fileObject->getForLocalProcessing(FALSE);
-               $imageInfo = @getimagesize($filePath);
-               $imageUrl = $this->siteURL . substr($filePath, strlen(PATH_site));
-               $this->imageInsertJS($imageUrl, $imageInfo[0], $imageInfo[1], $altText, $titleText, $additionalParams);
+       public function insertPlainImage(Resource\File $fileObject, $altText = '', $titleText = '', $additionalParams = '') {
+               $width = $fileObject->getProperty('width');
+               $height = $fileObject->getProperty('height');
+               if (!$width || !$height) {
+                       $filePath = $fileObject->getForLocalProcessing(FALSE);
+                       $imageInfo = @getimagesize($filePath);
+                       $width = $imageInfo[0];
+                       $height = $imageInfo[1];
+               }
+               $imageUrl = $fileObject->getPublicUrl();
+               // If file is local, make the url absolute
+               if (substr($imageUrl, 0, 4) !== 'http') {
+                       $imageUrl = $this->siteURL . $imageUrl;
+               }
+               $this->imageInsertJS($imageUrl, $width, $height, $altText, $titleText, $additionalParams);
        }
 
        /**
@@ -270,7 +277,7 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
 <body>
 <script type="text/javascript">
 /*<![CDATA[*/
-       insertImage(' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($url, 1) . ',' . $width . ',' . $height . ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($altText, 1) . ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($titleText, 1) . ',' . \TYPO3\CMS\Core\Utility\GeneralUtility::quoteJSvalue($additionalParams, 1) . ');
+       insertImage(' . GeneralUtility::quoteJSvalue($url, 1) . ',' . $width . ',' . $height . ',' . GeneralUtility::quoteJSvalue($altText, 1) . ',' . GeneralUtility::quoteJSvalue($titleText, 1) . ',' . GeneralUtility::quoteJSvalue($additionalParams, 1) . ');
 /*]]>*/
 </script>
 </body>
@@ -290,11 +297,11 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                $removedProperties = array();
                if (is_array($this->buttonConfig['properties.'])) {
                        if ($this->buttonConfig['properties.']['removeItems']) {
-                               $removedProperties = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['removeItems'], 1);
+                               $removedProperties = GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['removeItems'], TRUE);
                        }
                }
                if ($this->buttonConfig['properties.']['class.']['allowedClasses']) {
-                       $classesImageArray = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['class.']['allowedClasses'], 1);
+                       $classesImageArray = GeneralUtility::trimExplode(',', $this->buttonConfig['properties.']['class.']['allowedClasses'], TRUE);
                        $classesImageJSOptions = '<option value=""></option>';
                        foreach ($classesImageArray as $class) {
                                $classesImageJSOptions .= '<option value="' . $class . '">' . $class . '</option>';
@@ -312,10 +319,10 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                        var HTMLArea = window.parent.HTMLArea;
 
                        HTMLArea.TYPO3Image.insertElement = function (table, uid, type, filename, filePath, fileExt, fileIcon) {
-                               return jumpToUrl(\'?editorNo=\' + \'' . $editorNo . '\' + \'&insertImage=\' + filePath + \'&table=\' + table + \'&uid=\' + uid + \'&type=\' + type + \'bparams=\' + \'' . $this->bparams . '\');
+                               return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'editorNo=') . ' + \'' . $editorNo . '\' + \'&insertImage=\' + filePath + \'&table=\' + table + \'&uid=\' + uid + \'&type=\' + type + \'bparams=\' + \'' . $this->bparams . '\');
                        }
                        function insertElement(table, uid, type, fileName, filePath, fileExt, fileIcon, action, close) {
-                               return jumpToUrl(\'?editorNo=\' + \'' . $editorNo . '\' + \'&insertImage=\' + filePath + \'&table=\' + table + \'&uid=\' + uid + \'&type=\' + type + \'bparams=\' + \'' . $this->bparams . '\');
+                               return jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'editorNo=') . ' + \'' . $editorNo . '\' + \'&insertImage=\' + filePath + \'&table=\' + table + \'&uid=\' + uid + \'&type=\' + type + \'bparams=\' + \'' . $this->bparams . '\');
                        }
                        function initEventListeners() {
                                if (Ext.isWebKit) {
@@ -331,7 +338,7 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                                var cur_width = selectedImageRef ? "&cWidth="+selectedImageRef.style.width : "";
                                var cur_height = selectedImageRef ? "&cHeight="+selectedImageRef.style.height : "";
 
-                               var theLocation = URL+add_act+add_editorNo+add_sys_language_content+RTEtsConfigParams+cur_width+cur_height+(anchor?anchor:"");
+                               var theLocation = URL+add_act+add_editorNo+add_sys_language_content+RTEtsConfigParams+cur_width+cur_height+(typeof(anchor)=="string"?anchor:"");
                                window.location.href = theLocation;
                                return false;
                        }
@@ -340,7 +347,7 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                        }
                        function launchView(url) {
                                var thePreviewWindow="";
-                               thePreviewWindow = window.open("' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . 'show_item.php?table="+url,"ShowItem","height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
+                               thePreviewWindow = window.open("' . GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir . 'show_item.php?table="+url,"ShowItem","height=300,width=410,status=0,menubar=0,resizable=0,location=0,directories=0,scrollbars=1,toolbar=0");
                                if (thePreviewWindow && thePreviewWindow.focus) {
                                        thePreviewWindow.focus();
                                }
@@ -363,33 +370,32 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                                        });
                                        languageSelector += \'</select>\';
                                }
-                               var bgColor=\' class="bgColor4"\';
                                var sz="";
-                               sz+=\'<table border="0" cellpadding="1" cellspacing="1"><form action="" name="imageData">\';
+                               sz+=\'<form action="" name="imageData"><table class="htmlarea-window-table">\';
                                ' . (in_array('class', $removedProperties) ? '' : '
                                if(classesImage) {
-                                       sz+=\'<tr><td\'+bgColor+\'><label for="iClass">' . $GLOBALS['LANG']->getLL('class') . ': </label></td><td>\'+styleSelector+\'</td></tr>\';
+                                       sz+=\'<tr><td><label for="iClass">' . $GLOBALS['LANG']->getLL('class') . ': </label></td><td>\'+styleSelector+\'</td></tr>\';
                                }') . (in_array('width', $removedProperties) ? '' : '
                                if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && ' . $lockPlainWidth . ')) {
-                                       sz+=\'<tr><td\'+bgColor+\'><label for="iWidth">' . $GLOBALS['LANG']->getLL('width') . ': </label></td><td><input type="text" id="iWidth" name="iWidth" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';
+                                       sz+=\'<tr><td><label for="iWidth">' . $GLOBALS['LANG']->getLL('width') . ': </label></td><td><input type="text" id="iWidth" name="iWidth" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';
                                }') . (in_array('height', $removedProperties) ? '' : '
                                if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && ' . $lockPlainHeight . ')) {
-                                       sz+=\'<tr><td\'+bgColor+\'><label for="iHeight">' . $GLOBALS['LANG']->getLL('height') . ': </label></td><td><input type="text" id="iHeight" name="iHeight" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';
+                                       sz+=\'<tr><td><label for="iHeight">' . $GLOBALS['LANG']->getLL('height') . ': </label></td><td><input type="text" id="iHeight" name="iHeight" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';
                                }') . (in_array('border', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iBorder">' . $GLOBALS['LANG']->getLL('border') . ': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';') . (in_array('float', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iFloat">' . $GLOBALS['LANG']->getLL('float') . ': </label></td><td>\'+floatSelector+\'</td></tr>\';') . (in_array('paddingTop', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingTop">' . $GLOBALS['LANG']->getLL('padding_top') . ': </label></td><td><input type="text" id="iPaddingTop" name="iPaddingTop" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . '></td></tr>\';') . (in_array('paddingRight', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingRight">' . $GLOBALS['LANG']->getLL('padding_right') . ': </label></td><td><input type="text" id="iPaddingRight" name="iPaddingRight" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';') . (in_array('paddingBottom', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingBottom">' . $GLOBALS['LANG']->getLL('padding_bottom') . ': </label></td><td><input type="text" id="iPaddingBottom" name="iPaddingBottom" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';') . (in_array('paddingLeft', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iPaddingLeft">' . $GLOBALS['LANG']->getLL('padding_left') . ': </label></td><td><input type="text" id="iPaddingLeft" name="iPaddingLeft" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';') . (in_array('title', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iTitle">' . $GLOBALS['LANG']->getLL('title') . ': </label></td><td><input type="text" id="iTitle" name="iTitle"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /></td></tr>\';') . (in_array('alt', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iAlt">' . $GLOBALS['LANG']->getLL('alt') . ': </label></td><td><input type="text" id="iAlt" name="iAlt"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /></td></tr>\';') . (in_array('lang', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iBorder">' . $GLOBALS['LANG']->getLL('border') . ': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';') . (in_array('float', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iFloat">' . $GLOBALS['LANG']->getLL('float') . ': </label></td><td>\'+floatSelector+\'</td></tr>\';') . (in_array('paddingTop', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iPaddingTop">' . $GLOBALS['LANG']->getLL('padding_top') . ': </label></td><td><input type="text" id="iPaddingTop" name="iPaddingTop" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . '></td></tr>\';') . (in_array('paddingRight', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iPaddingRight">' . $GLOBALS['LANG']->getLL('padding_right') . ': </label></td><td><input type="text" id="iPaddingRight" name="iPaddingRight" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';') . (in_array('paddingBottom', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iPaddingBottom">' . $GLOBALS['LANG']->getLL('padding_bottom') . ': </label></td><td><input type="text" id="iPaddingBottom" name="iPaddingBottom" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';') . (in_array('paddingLeft', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iPaddingLeft">' . $GLOBALS['LANG']->getLL('padding_left') . ': </label></td><td><input type="text" id="iPaddingLeft" name="iPaddingLeft" value=""' . $GLOBALS['TBE_TEMPLATE']->formWidth(4) . ' /></td></tr>\';') . (in_array('title', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iTitle">' . $GLOBALS['LANG']->getLL('title') . ': </label></td><td><input type="text" id="iTitle" name="iTitle"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /></td></tr>\';') . (in_array('alt', $removedProperties) ? '' : '
+                               sz+=\'<tr><td><label for="iAlt">' . $GLOBALS['LANG']->getLL('alt') . ': </label></td><td><input type="text" id="iAlt" name="iAlt"' . $GLOBALS['TBE_TEMPLATE']->formWidth(20) . ' /></td></tr>\';') . (in_array('lang', $removedProperties) ? '' : '
                                if (plugin.getButton("Language")) {
-                                       sz+=\'<tr><td\'+bgColor+\'><label for="iLang">\' + plugin.editor.getPlugin("Language").localize(\'Language-Tooltip\') + \': </label></td><td>\' + languageSelector + \'</td></tr>\';
+                                       sz+=\'<tr><td><label for="iLang">\' + plugin.editor.getPlugin("Language").localize(\'Language-Tooltip\') + \': </label></td><td>\' + languageSelector + \'</td></tr>\';
                                }') . (in_array('clickenlarge', $removedProperties) || in_array('data-htmlarea-clickenlarge', $removedProperties) ? '' : '
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iClickEnlarge">' . $GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_ttc.php:image_zoom', 1) . ' </label></td><td><input type="checkbox" name="iClickEnlarge" id="iClickEnlarge" value="0" /></td></tr>\';') . '
-                               sz+=\'<tr><td><input type="submit" value="' . $GLOBALS['LANG']->getLL('update') . '" onClick="return setImageProperties();"></td></tr>\';
-                               sz+=\'</form></table>\';
+                               sz+=\'<tr><td><label for="iClickEnlarge">' . $GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_ttc.xlf:image_zoom', TRUE) . ' </label></td><td><input type="checkbox" name="iClickEnlarge" id="iClickEnlarge" value="0" /></td></tr>\';') . '
+                               sz+=\'<tr><td></td><td><input type="submit" value="' . $GLOBALS['LANG']->getLL('update') . '" onClick="return setImageProperties();"></td></tr>\';
+                               sz+=\'</table></form>\';
                                return sz;
                        }
                        function setImageProperties() {
@@ -601,8 +607,8 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
         * Session data for this class can be set from outside with this method.
         * Call after init()
         *
-        * @param       array           Session data array
-        * @return      array           Session data and boolean which indicates that data needs to be stored in session because it's changed
+        * @param array $data Session data array
+        * @return array Session data and boolean which indicates that data needs to be stored in session because it's changed
         * @todo Define visibility
         */
        public function processSessionData($data) {
@@ -625,39 +631,191 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        }
 
        /**
-        * [Describe function...]
+        * Rich Text Editor (RTE) image selector
         *
-        * @return      [type]          ...
-        * @todo Define visibility
+        * @param boolean $wiz Not used here, kept for method signature compatibility with parent class
+        * @return string Modified content variable.
+        * @return string
         */
-       public function main_rte() {
+       public function main_rte($wiz = FALSE) {
                // Starting content:
-               $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Image', 1));
-               // Making menu in top:
+               $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Image', TRUE));
+
+               $this->content .= $this->doc->getTabMenuRaw($this->buildMenuArray($wiz, $this->allowedItems));
+               switch ($this->act) {
+                       case 'image':
+                               $JScode = '
+                                       document.write(printCurrentImageOptions());
+                                       insertImagePropertiesInForm();';
+                               $this->content .= '<br />' . $this->doc->wrapScriptTags($JScode);
+                               break;
+                       case 'plain':
+
+                       case 'magic':
+                               // Create folder tree:
+                               $foldertree = GeneralUtility::makeInstance('TYPO3\\CMS\\Rtehtmlarea\\FolderTree');
+                               $foldertree->thisScript = $this->thisScript;
+                               $tree = $foldertree->getBrowsableTree();
+                               // Get currently selected folder
+                               if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
+                                       $cmpPath = '';
+                               } else {
+                                       $cmpPath = $this->curUrlInfo['value'];
+                                       if (!isset($this->expandFolder)) {
+                                               $this->expandFolder = $cmpPath;
+                                       }
+                               }
+                               // Get the selected folder
+                               $selectedFolder = FALSE;
+                               if ($this->expandFolder) {
+                                       $fileOrFolderObject = NULL;
+                                       try {
+                                               $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                                       } catch (\Exception $e) {
+                                               // No path is selected
+                                       }
+                                       if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
+                                               // it's a folder
+                                               $selectedFolder = $fileOrFolderObject;
+                                       } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
+                                               // it's a file
+                                               $selectedFolder = $fileOrFolderObject->getParentFolder();
+                                       }
+                               }
+                               // If no folder is selected, get the user's default upload folder
+                               if (!$selectedFolder) {
+                                       try {
+                                               $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
+                                       } catch (\Exception $e) {
+                                               // The configured default user folder does not exist
+                                       }
+                               }
+                               // Build the file upload and folder creation form
+                               $uploadForm = '';
+                               $createFolder = '';
+                               if ($selectedFolder) {
+                                       $uploadForm = $this->uploadForm($selectedFolder);
+                                       $createFolder = $this->createFolder($selectedFolder);
+                               }
+                               // Insert the upload form on top, if so configured
+                               if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
+                                       $this->content .= $uploadForm;
+                               }
+                               // Render the filelist if there is a folder selected
+                               $files = '';
+                               if ($selectedFolder) {
+                                       $files = $this->TBE_expandFolder($selectedFolder, $this->act === 'plain' ? self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS : $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInRTEimageSelect'));
+                               }
+                               // Setup filelist indexed elements:
+                               $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
+                               // Wrap tree
+                               $this->content .= '
+
+                               <!--
+                                       Wrapper table for folder tree / file/folder list:
+                               -->
+                                               <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
+                                                       <tr>
+                                                               <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
+                                                               <td class="c-wCell" valign="top">' . $files . '</td>
+                                                       </tr>
+                                               </table>
+                                               ';
+                               // Add help message
+                               $helpMessage = $this->getHelpMessage($this->act);
+                               if ($helpMessage) {
+                                       $this->content .= $this->getMsgBox($helpMessage);
+                               }
+                               // Adding create folder + upload form if applicable
+                               if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
+                                       $this->content .= $uploadForm;
+                               }
+                               $this->content .= $createFolder;
+                               $this->content .= '<br />';
+                               break;
+                       case 'dragdrop':
+                               $foldertree = GeneralUtility::makeInstance('TBE_FolderTree');
+                               $foldertree->thisScript = $this->thisScript;
+                               $foldertree->ext_noTempRecyclerDirs = TRUE;
+                               $tree = $foldertree->getBrowsableTree();
+                               // Get currently selected folder
+                               if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
+                                       $cmpPath = '';
+                               } else {
+                                       $cmpPath = $this->curUrlInfo['value'];
+                                       if (!isset($this->expandFolder)) {
+                                               $this->expandFolder = $cmpPath;
+                                       }
+                               }
+                               $selectedFolder = FALSE;
+                               if ($this->expandFolder) {
+                                       try {
+                                               $selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
+                                       } catch (\Exception $e) {
+                                       }
+                               }
+                               // Render the filelist if there is a folder selected
+                               $files = '';
+                               if ($selectedFolder) {
+                                       $files = $this->TBE_dragNDrop($selectedFolder, implode(',', $this->allowedFileTypes));
+                               }
+                               // Wrap tree
+                               $this->content .= '<table border="0" cellpadding="0" cellspacing="0">
+                                       <tr>
+                                               <td style="vertical-align: top;">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
+                                               <td>&nbsp;</td>
+                                               <td style="vertical-align: top;">' . $files . '</td>
+                                       </tr>
+                                       </table>';
+                               break;
+                       default:
+                               // Call hook
+                               foreach ($this->hookObjects as $hookObject) {
+                                       $this->content .= $hookObject->getTab($this->act);
+                               }
+               }
+               $this->content .= $this->doc->endPage();
+
+               // unset the default jumpToUrl() function
+               unset($this->doc->JScodeArray['jumpToUrl']);
+
+               $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode($this->act, $this->editorNo, $this->sys_language_content);
+               $this->content = $this->doc->insertStylesAndJS($this->content);
+               return $this->content;
+       }
+
+       /**
+        * Returns an array definition of the top menu
+        *
+        * @param $wiz
+        * @param $allowedItems
+        * @return array
+        */
+       protected function buildMenuArray($wiz, $allowedItems) {
                $menuDef = array();
-               if (in_array('image', $this->allowedItems) && ($this->act === 'image' || \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('cWidth'))) {
+               if (in_array('image', $this->allowedItems) && ($this->act === 'image' || GeneralUtility::_GP('cWidth'))) {
                        $menuDef['image']['isActive'] = FALSE;
-                       $menuDef['image']['label'] = $GLOBALS['LANG']->getLL('currentImage', 1);
+                       $menuDef['image']['label'] = $GLOBALS['LANG']->getLL('currentImage', TRUE);
                        $menuDef['image']['url'] = '#';
-                       $menuDef['image']['addParams'] = 'onClick="jumpToUrl(\'?act=image&bparams=' . $this->bparams . '\');return false;"';
+                       $menuDef['image']['addParams'] = 'onClick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=image&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('magic', $this->allowedItems)) {
                        $menuDef['magic']['isActive'] = FALSE;
-                       $menuDef['magic']['label'] = $GLOBALS['LANG']->getLL('magicImage', 1);
+                       $menuDef['magic']['label'] = $GLOBALS['LANG']->getLL('magicImage', TRUE);
                        $menuDef['magic']['url'] = '#';
-                       $menuDef['magic']['addParams'] = 'onClick="jumpToUrl(\'?act=magic&bparams=' . $this->bparams . '\');return false;"';
+                       $menuDef['magic']['addParams'] = 'onClick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=magic&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('plain', $this->allowedItems)) {
                        $menuDef['plain']['isActive'] = FALSE;
-                       $menuDef['plain']['label'] = $GLOBALS['LANG']->getLL('plainImage', 1);
+                       $menuDef['plain']['label'] = $GLOBALS['LANG']->getLL('plainImage', TRUE);
                        $menuDef['plain']['url'] = '#';
-                       $menuDef['plain']['addParams'] = 'onClick="jumpToUrl(\'?act=plain&bparams=' . $this->bparams . '\');return false;"';
+                       $menuDef['plain']['addParams'] = 'onClick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=plain&bparams=' . $this->bparams) . ');return false;"';
                }
                if (in_array('dragdrop', $this->allowedItems)) {
                        $menuDef['dragdrop']['isActive'] = FALSE;
-                       $menuDef['dragdrop']['label'] = $GLOBALS['LANG']->getLL('dragDropImage', 1);
+                       $menuDef['dragdrop']['label'] = $GLOBALS['LANG']->getLL('dragDropImage', TRUE);
                        $menuDef['dragdrop']['url'] = '#';
-                       $menuDef['dragdrop']['addParams'] = 'onClick="jumpToUrl(\'?act=dragdrop&bparams=' . $this->bparams . '\');return false;"';
+                       $menuDef['dragdrop']['addParams'] = 'onClick="jumpToUrl(' . GeneralUtility::quoteJSvalue($this->getThisScript() . 'act=dragdrop&bparams=' . $this->bparams) . ');return false;"';
                }
                // Call hook for extra options
                foreach ($this->hookObjects as $hookObject) {
@@ -671,138 +829,7 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                        $this->act = key($menuDef);
                }
                $menuDef[$this->act]['isActive'] = TRUE;
-               $this->content .= $this->doc->getTabMenuRaw($menuDef);
-               switch ($this->act) {
-               case 'image':
-                       $JScode = '
-                               document.write(printCurrentImageOptions());
-                               insertImagePropertiesInForm();';
-                       $this->content .= '<br />' . $this->doc->wrapScriptTags($JScode);
-                       break;
-               case 'plain':
-
-               case 'magic':
-                       // Create folder tree:
-                       $foldertree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Rtehtmlarea\\ImageFolderTree');
-                       $foldertree->thisScript = $this->thisScript;
-                       $tree = $foldertree->getBrowsableTree();
-                       // Get currently selected folder
-                       if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
-                               $cmpPath = '';
-                       } else {
-                               $cmpPath = $this->curUrlInfo['value'];
-                               if (!isset($this->expandFolder)) {
-                                       $this->expandFolder = $cmpPath;
-                               }
-                       }
-                       // Get the selected folder
-                       if ($this->expandFolder) {
-                               $selectedFolder = FALSE;
-                               $fileOrFolderObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
-                               if ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\Folder) {
-                                       // it's a folder
-                                       $selectedFolder = $fileOrFolderObject;
-                               } elseif ($fileOrFolderObject instanceof \TYPO3\CMS\Core\Resource\FileInterface) {
-                                       // it's a file
-                                       // @todo: find the parent folder, right now done a bit ugly, because the file does not
-                                       // support finding the parent folder of a file on purpose
-                                       $folderIdentifier = dirname($fileOrFolderObject->getIdentifier());
-                                       $selectedFolder = $fileOrFolderObject->getStorage()->getFolder($folderIdentifier);
-                               }
-                       }
-                       // If no folder is selected, get the user's default upload folder
-                       if (!$selectedFolder) {
-                               $selectedFolder = $GLOBALS['BE_USER']->getDefaultUploadFolder();
-                       }
-                       // Build the file upload and folder creation form
-                       $uploadForm = '';
-                       $createFolder = '';
-                       if ($selectedFolder && !$this->isReadOnlyFolder($selectedFolder)) {
-                               $uploadForm = $this->uploadForm($selectedFolder);
-                               if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
-                                       $createFolder = $this->createFolder($selectedFolder);
-                               }
-                       }
-                       // Insert the upload form on top, if so configured
-                       if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
-                               $this->content .= $uploadForm;
-                       }
-                       // Render the filelist if there is a folder selected
-                       if ($selectedFolder) {
-                               $files = $this->TBE_expandFolder($selectedFolder, $this->act === 'plain' ? 'jpg,jpeg,gif,png' : $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInRTEimageSelect'));
-                       }
-                       // Setup filelist indexed elements:
-                       $this->doc->JScode .= $this->doc->wrapScriptTags('BrowseLinks.addElements(' . json_encode($this->elements) . ');');
-                       // Wrap tree
-                       $this->content .= '
-
-                       <!--
-                               Wrapper table for folder tree / file/folder list:
-                       -->
-                                       <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkFiles">
-                                               <tr>
-                                                       <td class="c-wCell" valign="top">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
-                                                       <td class="c-wCell" valign="top">' . $files . '</td>
-                                               </tr>
-                                       </table>
-                                       ';
-                       // Add help message
-                       $helpMessage = $this->getHelpMessage($this->act);
-                       if ($helpMessage) {
-                               $this->content .= $this->getMsgBox($helpMessage);
-                       }
-                       // Adding create folder + upload form if applicable
-                       if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
-                               $this->content .= $uploadForm;
-                       }
-                       $this->content .= $createFolder;
-                       $this->content .= '<br />';
-                       break;
-               case 'dragdrop':
-                       $foldertree = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TBE_FolderTree');
-                       $foldertree->thisScript = $this->thisScript;
-                       $foldertree->ext_noTempRecyclerDirs = TRUE;
-                       $tree = $foldertree->getBrowsableTree();
-                       // Get currently selected folder
-                       if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
-                               $cmpPath = '';
-                       } else {
-                               $cmpPath = $this->curUrlInfo['value'];
-                               if (!isset($this->expandFolder)) {
-                                       $this->expandFolder = $cmpPath;
-                               }
-                       }
-                       if ($this->expandFolder) {
-                               try {
-                                       $selectedFolder = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFolderObjectFromCombinedIdentifier($this->expandFolder);
-                               } catch (Exception $e) {
-                                       $selectedFolder = FALSE;
-                               }
-                       }
-                       // Render the filelist if there is a folder selected
-                       if ($selectedFolder) {
-                               $files = $this->TBE_dragNDrop($selectedFolder, implode(',', $this->allowedFileTypes));
-                       }
-                       // Wrap tree
-                       $this->content .= '<table border="0" cellpadding="0" cellspacing="0">
-                               <tr>
-                                       <td style="vertical-align: top;">' . $this->barheader(($GLOBALS['LANG']->getLL('folderTree') . ':')) . $tree . '</td>
-                                       <td>&nbsp;</td>
-                                       <td style="vertical-align: top;">' . $files . '</td>
-                               </tr>
-                               </table>';
-                       break;
-               default:
-                       // Call hook
-                       foreach ($this->hookObjects as $hookObject) {
-                               $this->content .= $hookObject->getTab($this->act);
-                       }
-                       break;
-               }
-               $this->content .= $this->doc->endPage();
-               $this->doc->JScodeArray['rtehtmlarea'] = $this->getJSCode($this->act, $this->editorNo, $this->sys_language_content);
-               $this->content = $this->doc->insertStylesAndJS($this->content);
-               return $this->content;
+               return $menuDef;
        }
 
        /**
@@ -814,20 +841,8 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                $this->thisConfig = $this->getRTEConfig();
                $this->buttonConfig = $this->getButtonConfig();
                $this->imgPath = $this->getImgPath();
-               $this->RTEImageStorageDir = $this->getRTEImageStorageDir();
                $this->defaultClass = $this->getDefaultClass();
-               $this->setMaximumImageDimensions();
-       }
-
-       /**
-        * Get the RTE configuration from Page TSConfig
-        *
-        * @return      array           RTE configuration array
-        */
-       protected function getRTEConfig() {
-               $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
-               $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE', \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($RTEtsConfigParts[5]));
-               return \TYPO3\CMS\Backend\Utility\BackendUtility::RTEsetup($RTEsetup['properties'], $RTEtsConfigParts[0], $RTEtsConfigParts[2], $RTEtsConfigParts[4]);
+               $this->setMaximumPlainImageDimensions();
        }
 
        /**
@@ -852,12 +867,12 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        /**
         * Get the allowed items or tabs
         *
-        * @param       string          $items: initial list of possible items
-        * @return      array           the allowed items
+        * @param string $items: initial list of possible items
+        * @return array the allowed items
         */
        public function getAllowedItems($items) {
                $allowedItems = explode(',', $items);
-               $clientInfo = \TYPO3\CMS\Core\Utility\GeneralUtility::clientInfo();
+               $clientInfo = GeneralUtility::clientInfo();
                if ($clientInfo['BROWSER'] !== 'opera') {
                        $allowedItems[] = 'dragdrop';
                }
@@ -871,7 +886,7 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                }
                // Remove options according to RTE configuration
                if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
-                       $allowedItems = array_diff($allowedItems, \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['removeItems'], 1));
+                       $allowedItems = array_diff($allowedItems, GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['removeItems'], TRUE));
                }
                return $allowedItems;
        }
@@ -885,7 +900,7 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        public function orderMenuDefinition($menuDefinition) {
                $orderedMenuDefinition = array();
                if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['orderItems']) {
-                       $orderItems = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['orderItems'], TRUE);
+                       $orderItems = GeneralUtility::trimExplode(',', $this->buttonConfig['options.']['orderItems'], TRUE);
                        $orderItems = array_intersect($orderItems, $this->allowedItems);
                        foreach ($orderItems as $item) {
                                $orderedMenuDefinition[$item] = $menuDefinition[$item];
@@ -912,11 +927,11 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
        }
 
        /**
-        * Set variables for maximum image dimensions
+        * Set variables for maximum plain image dimensions
         *
         * @return      void
         */
-       protected function setMaximumImageDimensions() {
+       protected function setMaximumPlainImageDimensions() {
                if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
                        if ($this->buttonConfig['options.']['plain.']['maxWidth']) {
                                $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
@@ -931,21 +946,6 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                if (!$this->plainMaxHeight) {
                        $this->plainMaxHeight = 680;
                }
-               if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
-                       if ($this->buttonConfig['options.']['magic.']['maxWidth']) {
-                               $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
-                       }
-                       if ($this->buttonConfig['options.']['magic.']['maxHeight']) {
-                               $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
-                       }
-               }
-               // These defaults allow images to be based on their width - to a certain degree - by setting a high height. Then we're almost certain the image will be based on the width
-               if (!$this->magicMaxWidth) {
-                       $this->magicMaxWidth = 300;
-               }
-               if (!$this->magicMaxHeight) {
-                       $this->magicMaxHeight = 1000;
-               }
        }
 
        /**
@@ -956,149 +956,34 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
         */
        public function getHelpMessage($act) {
                switch ($act) {
-               case 'plain':
-                       return sprintf($GLOBALS['LANG']->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
-                       break;
-               case 'magic':
-                       return sprintf($GLOBALS['LANG']->getLL('magicImage_msg'));
-                       break;
-               default:
-                       return '';
+                       case 'plain':
+                               return sprintf($GLOBALS['LANG']->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
+                               break;
+                       case 'magic':
+                               return sprintf($GLOBALS['LANG']->getLL('magicImage_msg'));
+                               break;
+                       default:
+                               return '';
                }
        }
 
        /**
-        * Render list of files.
+        * Checks if the given file is selectable in the file list.
         *
-        * @param       array           List of files. See t3lib_div::getFilesInDir
-        * @param       string          If set a header with a folder icon and folder name are shown
-        * @param       boolean         Whether to show thumbnails or not. If set, no thumbnails are shown.
-        * @return      string          HTML output
-        * @todo Define visibility
+        * In "plain" RTE mode only image files with a maximum width and height are selectable.
+        *
+        * @param \TYPO3\CMS\Core\Resource\FileInterface $file
+        * @param array $imgInfo Image dimensions from \TYPO3\CMS\Core\Imaging\GraphicalFunctions::getImageDimensions()
+        * @return bool TRUE if file is selectable.
         */
-       public function fileList(array $files, \TYPO3\CMS\Core\Resource\Folder $folder = NULL, $noThumbs = 0) {
-               $out = '';
-               // Listing the files:
-               if (is_array($files)) {
-                       $lines = array();
-                       // Create headline (showing number of files):
-                       $filesCount = count($files);
-                       $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
-                       $out .= '<div id="filelist">';
-                       $out .= $this->getBulkSelector($filesCount);
-                       $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
-                       // Create the header of current folder:
-                       if ($folder) {
-                               $folderIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder');
-                               $lines[] = '<tr class="t3-row-header">
-                                       <td colspan="4">' . $folderIcon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
-                               </tr>';
-                       }
-                       if ($filesCount == 0) {
-                               $lines[] = '
-                                       <tr class="file_list_normal">
-                                               <td colspan="4">No files found.</td>
-                                       </tr>';
-                       }
-                       // Init graphic object for reading file and image dimensions:
-                       /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
-                       $imgObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
-                       $imgObj->init();
-                       $imgObj->mayScaleUp = 0;
-                       $imgObj->tempPath = PATH_site . $imgObj->tempPath;
-                       // Traverse the file list:
-                       /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
-                       foreach ($files as $fileObject) {
-                               $fileExtension = $fileObject->getExtension();
-                               // Thumbnail/size generation:
-                               if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
-                                       $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 64, 'height' => 64))->getPublicUrl(TRUE);
-                                       $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
-                                       $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
-                                       $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1"';
-                               } else {
-                                       $clickIcon = '';
-                                       $pDim = '';
-                               }
-                               // Create file icon:
-                               $size = ' (' . \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
-                               $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
-                               // Create links for adding the file:
-                               $filesIndex = count($this->elements);
-                               $this->elements['file_' . $filesIndex] = array(
-                                       'type' => 'file',
-                                       'table' => 'sys_file',
-                                       'uid' => $fileObject->getUid(),
-                                       'fileName' => $fileObject->getName(),
-                                       'filePath' => $fileObject->getUid(),
-                                       'fileExt' => $fileExtension,
-                                       'fileIcon' => $icon
-                               );
-                               $element = $this->elements['file_' . $filesIndex];
-                               if ($this->act === 'plain' && ($imgInfo[0] > $this->plainMaxWidth || $imgInfo[1] > $this->plainMaxHeight) || !\TYPO3\CMS\Core\Utility\GeneralUtility::inList('jpg,jpeg,gif,png', $fileExtension)) {
-                                       $ATag = '';
-                                       $ATag_alt = '';
-                                       $ATag_e = '';
-                               } else {
-                                       $this->elements['file_' . $filesIndex] = array(
-                                               'type' => 'file',
-                                               'table' => 'sys_file',
-                                               'uid' => $fileObject->getUid(),
-                                               'fileName' => $fileObject->getName(),
-                                               'filePath' => $fileObject->getUid(),
-                                               'fileExt' => $fileExtension,
-                                               'fileIcon' => $icon
-                                       );
-                                       $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
-                                       $ATag_alt = substr($ATag, 0, -4) . ',1);">';
-                                       $ATag_e = '</a>';
-                               }
-                               // Create link to showing details about the file in a window:
-                               $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=' . rawurlencode($fileObject->getCombinedIdentifier()) . '&returnUrl=' . rawurlencode(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI'));
-                               $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
-                               $ATag2_e = '</a>';
-                               // Combine the stuff:
-                               $filenameAndIcon = $ATag_alt . $icon . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
-                               // Show element:
-                               if ($pDim) {
-                                       // Image...
-                                       $lines[] = '
-                                               <tr class="file_list_normal">
-                                                       <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                                       <td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', 1) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', 1) . $ATag2_e) . '</td>
-                                                       <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
-                                               </tr>';
-                                       $lines[] = '
-                                               <tr>
-                                                       <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
-                                               </tr>';
-                               } else {
-                                       $lines[] = '
-                                               <tr class="file_list_normal">
-                                                       <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                                       <td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', 1) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', 1) . $ATag2_e) . '</td>
-                                                       <td>&nbsp;</td>
-                                               </tr>';
-                               }
-                       }
-                       // Wrap all the rows in table tags:
-                       $out .= '
-
-
-
-               <!--
-                       File listing
-               -->
-                               <table cellpadding="0" cellspacing="0" id="typo3-filelist">
-                                       ' . implode('', $lines) . '
-                               </table>';
-               }
-               // Return accumulated content for filelisting:
-               $out .= '</div>';
-               return $out;
+       protected function fileIsSelectableInFileList(\TYPO3\CMS\Core\Resource\FileInterface $file, array $imgInfo) {
+               return (
+                       $this->act !== 'plain'
+                       || (
+                               GeneralUtility::inList(self::PLAIN_MODE_IMAGE_FILE_EXTENSIONS, strtolower($file->getExtension()))
+                               && $imgInfo[0] <= $this->plainMaxWidth
+                               && $imgInfo[1] <= $this->plainMaxHeight
+                       )
+               );
        }
-
 }
-
-
-?>
\ No newline at end of file