[FEATURE] Use File Abstraction Layer in RTE
authorTYPO3 FAL Team <typo3v4@typo3.org>
Fri, 20 Apr 2012 16:33:15 +0000 (18:33 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 28 Apr 2012 13:58:46 +0000 (15:58 +0200)
Change-Id: Ifd6c313eeab812b511b8ae9ae893cc399244b590
Resolves: #36387
Releases: 6.0
Reviewed-on: http://review.typo3.org/10656
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
t3lib/class.t3lib_parsehtml_proc.php
typo3/sysext/rtehtmlarea/ext_localconf.php
typo3/sysext/rtehtmlarea/extensions/TYPO3Image/ext_localconf.php [new file with mode: 0644]
typo3/sysext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php
typo3/sysext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php

index ddba25e..8e2bbf4 100644 (file)
@@ -346,18 +346,43 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                $pI = pathinfo($pU['path']);
 
                                                if (t3lib_div::inList('gif,png,jpeg,jpg', strtolower($pI['extension']))) {
-                                                       $filename = t3lib_div::shortMD5($absRef) . '.' . $pI['extension'];
-                                                       $origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicP_' . $filename;
-                                                       $C_origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicC_' . $filename . '.' . $pI['extension'];
-                                                       if (!@is_file($origFilePath)) {
-                                                               t3lib_div::writeFile($origFilePath, $externalFile);
-                                                               t3lib_div::writeFile($C_origFilePath, $externalFile);
-                                                       }
-                                                       $absRef = $siteUrl . $this->rteImageStorageDir() . 'RTEmagicC_' . $filename . '.' . $pI['extension'];
+                                                       $fileName = t3lib_div::shortMD5($absRef) . '.' . $pI['extension'];
+                                                       $folder = t3lib_file_Factory::getInstance()->getFolderObjectFromCombinedIdentifier(
+                                                               $this->rteImageStorageDir()
+                                                       );
+
+                                                       if ($folder instanceof t3lib_file_Folder) {
+                                                               $fileObject = $folder->createFile($fileName)->setContents($externalFile);
+
+                                                               /** @var $magicImageService t3lib_file_Service_MagicImageService */
+                                                               $magicImageService = t3lib_div::makeInstance('t3lib_file_Service_MagicImageService');
+
+                                                               $imageConfiguration = array(
+                                                                       'width' => $attribArray['width'],
+                                                                       'height' => $attribArray['height'],
+                                                                       'maxW' => 300,
+                                                                       'maxH' => 1000,
+                                                               );
+
+                                                               $magicImage = $magicImageService->createMagicImage(
+                                                                       $fileObject,
+                                                                       $imageConfiguration,
+                                                                       $this->rteImageStorageDir()
+                                                               );
+
+                                                               if ($magicImage instanceof t3lib_file_FileInterface) {
+                                                                       $filePath = $magicImage->getForLocalProcessing(FALSE);
+                                                                       $imageInfo = @getimagesize($filePath);
+                                                                       $attribArray['width'] = $imageInfo[0];
+                                                                       $attribArray['height'] = $imageInfo[1];
+                                                                       $attribArray['data-htmlarea-file-uid'] = $fileObject->getUid();
+                                                                       $absRef = $siteUrl . substr($filePath, strlen(PATH_site));
+                                                               }
 
-                                                       $attribArray['src'] = $absRef;
-                                                       $params = t3lib_div::implodeAttributes($attribArray, 1);
-                                                       $imgSplit[$k] = '<img ' . $params . ' />';
+                                                               $attribArray['src'] = $absRef;
+                                                               $params = t3lib_div::implodeAttributes($attribArray, 1);
+                                                               $imgSplit[$k] = '<img ' . $params . ' />';
+                                                       }
                                                }
                                        }
                                }
@@ -369,79 +394,105 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
 
                                                // Check file existence (in relative dir to this installation!)
                                        if ($filepath && @is_file($filepath)) {
-
                                                        // If "magic image":
-                                               $pathPre = $this->rteImageStorageDir() . 'RTEmagicC_';
-                                               if (t3lib_div::isFirstPartOfStr($path, $pathPre)) {
-                                                               // Find original file:
-                                                       $pI = pathinfo(substr($path, strlen($pathPre)));
-                                                       $filename = substr($pI['basename'], 0, -strlen('.' . $pI['extension']));
-                                                       $origFilePath = PATH_site . $this->rteImageStorageDir() . 'RTEmagicP_' . $filename;
-                                                       if (@is_file($origFilePath)) {
-                                                               $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
-                                                               $imgObj->init();
-                                                               $imgObj->mayScaleUp = 0;
-                                                               $imgObj->tempPath = PATH_site . $imgObj->tempPath;
-
-                                                               $curInfo = $imgObj->getImageDimensions($filepath); // Image dimensions of the current image
-                                                               $curWH = $this->getWHFromAttribs($attribArray); // Image dimensions as set in the image tag
-                                                                       // Compare dimensions:
-                                                               if ($curWH[0] != $curInfo[0] || $curWH[1] != $curInfo[1]) {
-                                                                       $origImgInfo = $imgObj->getImageDimensions($origFilePath); // Image dimensions of the current image
-                                                                       $cW = $curWH[0];
-                                                                       $cH = $curWH[1];
-                                                                       $cH = 1000; // Make the image based on the width solely...
-                                                                       $imgI = $imgObj->imageMagickConvert($origFilePath, $pI['extension'], $cW . 'm', $cH . 'm');
-                                                                       if ($imgI[3]) {
-                                                                               $fI = pathinfo($imgI[3]);
-                                                                               @copy($imgI[3], $filepath); // Override the child file
-                                                                                       // Removing width and heigth form style attribute
-                                                                               $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
-                                                                               $attribArray['width'] = $imgI[0];
-                                                                               $attribArray['height'] = $imgI[1];
-                                                                               $params = t3lib_div::implodeAttributes($attribArray, 1);
-                                                                               $imgSplit[$k] = '<img ' . $params . ' />';
+                                               $folder = t3lib_file_Factory::getInstance()->getFolderObjectFromCombinedIdentifier(
+                                                       $this->rteImageStorageDir()
+                                               );
+
+                                               if ($folder instanceof t3lib_file_Folder) {
+                                                       $storageConfiguration = $folder->getStorage()->getConfiguration();
+                                                       $rteImageStorageDir = rtrim($storageConfiguration['basePath'], '/') . '/' . $folder->getName() .'/';
+                                                       $pathPre = $rteImageStorageDir . 'RTEmagicC_';
+
+                                                       if (t3lib_div::isFirstPartOfStr($path, $pathPre)) {
+                                                                       // Find original file
+                                                               if ($attribArray['data-htmlarea-file-uid']) {
+                                                                       $originalFileObject = t3lib_file_Factory::getInstance()->getFileObject(
+                                                                               $attribArray['data-htmlarea-file-uid']
+                                                                       );
+                                                               } else {
+                                                                               // Backward compatibility mode
+                                                                       $pI = pathinfo(substr($path, strlen($pathPre)));
+                                                                       $filename = substr($pI['basename'], 0, -strlen('.' . $pI['extension']));
+                                                                       $origFilePath = PATH_site . $rteImageStorageDir . 'RTEmagicP_' . $filename;
+                                                                       if (@is_file($origFilePath)) {
+                                                                               $originalFileObject = $folder->addFile($origFilePath, $filename, 'changeName');
+                                                                               $attribArray['data-htmlarea-file-uid'] = $originalFileObject->getUid();
                                                                        }
                                                                }
-                                                       }
 
-                                               } elseif ($this->procOptions['plainImageMode']) { // If "plain image" has been configured:
-
-                                                               // Image dimensions as set in the image tag, if any
-                                                       $curWH = $this->getWHFromAttribs($attribArray);
-                                                       if ($curWH[0]) {
-                                                               $attribArray['width'] = $curWH[0];
-                                                       }
-                                                       if ($curWH[1]) {
-                                                               $attribArray['height'] = $curWH[1];
-                                                       }
-
-                                                               // Removing width and heigth form style attribute
-                                                       $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
-
-                                                               // Finding dimensions of image file:
-                                                       $fI = @getimagesize($filepath);
-
-                                                               // Perform corrections to aspect ratio based on configuration:
-                                                       switch ((string) $this->procOptions['plainImageMode']) {
-                                                               case 'lockDimensions':
-                                                                       $attribArray['width'] = $fI[0];
-                                                                       $attribArray['height'] = $fI[1];
-                                                               break;
-                                                               case 'lockRatioWhenSmaller': // If the ratio has to be smaller, then first set the width...:
-                                                                       if ($attribArray['width'] > $fI[0]) {
-                                                                               $attribArray['width'] = $fI[0];
-                                                                       }
-                                                               case 'lockRatio':
-                                                                       if ($fI[0] > 0) {
-                                                                               $attribArray['height'] = round($attribArray['width'] * ($fI[1] / $fI[0]));
+                                                               if (!empty($originalFileObject) && $originalFileObject instanceof t3lib_file_FileInterface) {
+                                                                       /** @var $magicImageService t3lib_file_Service_MagicImageService */
+                                                                       $magicImageService = t3lib_div::makeInstance('t3lib_file_Service_MagicImageService');
+                                                                               // Image dimensions of the current image
+                                                                       $imageDimensions = @getimagesize($filepath);
+                                                                               // Image dimensions as set on the img tag
+                                                                       $imgTagDimensions = $this->getWHFromAttribs($attribArray);
+                                                                               // If the dimensions have changed, we re-create the magic image
+                                                                       if ($imgTagDimensions[0] != $imageDimensions[0] || $imgTagDimensions[1] != $imageDimensions[1]) {
+                                                                               $imageConfiguration = array(
+                                                                                       'width' => $imgTagDimensions[0],
+                                                                                       'height' => $imgTagDimensions[1],
+                                                                                       'maxW' => 300,
+                                                                                       'maxH' => 1000,
+                                                                               );
+                                                                                       // TODO: Perhaps the existing magic image should be overridden?
+                                                                               $magicImage = $magicImageService->createMagicImage(
+                                                                                       $originalFileObject,
+                                                                                       $imageConfiguration,
+                                                                                       $this->rteImageStorageDir()
+                                                                               );
+
+                                                                               if ($magicImage instanceof t3lib_file_FileInterface) {
+                                                                                       $filePath = $magicImage->getForLocalProcessing(FALSE);
+                                                                                       $imageInfo = @getimagesize($filePath);
+                                                                                               // Removing width and heigth from any style attribute
+                                                                                       $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
+                                                                                       $attribArray['width'] = $imageInfo[0];
+                                                                                       $attribArray['height'] = $imageInfo[1];
+                                                                                       $attribArray['src'] = $this->siteURL() . substr($filePath, strlen(PATH_site));
+                                                                                       $params = t3lib_div::implodeAttributes($attribArray, 1);
+                                                                                       $imgSplit[$k] = '<img ' . $params . ' />';
+                                                                               }
                                                                        }
-                                                               break;
+                                                               }
+                                                       } elseif ($this->procOptions['plainImageMode']) { // If "plain image" has been configured:
+                                                                       // Image dimensions as set in the image tag, if any
+                                                               $curWH = $this->getWHFromAttribs($attribArray);
+                                                               if ($curWH[0]) {
+                                                                       $attribArray['width'] = $curWH[0];
+                                                               }
+                                                               if ($curWH[1]) {
+                                                                       $attribArray['height'] = $curWH[1];
+                                                               }
+       
+                                                                       // Removing width and heigth form style attribute
+                                                               $attribArray['style'] = preg_replace('/((?:^|)\s*(?:width|height)\s*:[^;]*(?:$|;))/si', '', $attribArray['style']);
+       
+                                                                       // Finding dimensions of image file:
+                                                               $fI = @getimagesize($filepath);
+       
+                                                                       // Perform corrections to aspect ratio based on configuration:
+                                                               switch ((string) $this->procOptions['plainImageMode']) {
+                                                                       case 'lockDimensions':
+                                                                               $attribArray['width'] = $fI[0];
+                                                                               $attribArray['height'] = $fI[1];
+                                                                       break;
+                                                                       case 'lockRatioWhenSmaller': // If the ratio has to be smaller, then first set the width...:
+                                                                               if ($attribArray['width'] > $fI[0]) {
+                                                                                       $attribArray['width'] = $fI[0];
+                                                                               }
+                                                                       case 'lockRatio':
+                                                                               if ($fI[0] > 0) {
+                                                                                       $attribArray['height'] = round($attribArray['width'] * ($fI[1] / $fI[0]));
+                                                                               }
+                                                                       break;
+                                                               }
+       
+                                                                       // Compile the image tag again:
+                                                               $params = t3lib_div::implodeAttributes($attribArray, 1);
+                                                               $imgSplit[$k] = '<img ' . $params . ' />';
                                                        }
-
-                                                               // Compile the image tag again:
-                                                       $params = t3lib_div::implodeAttributes($attribArray, 1);
-                                                       $imgSplit[$k] = '<img ' . $params . ' />';
                                                }
                                        } else { // Remove image if it was not found in a proper position on the server!
 
@@ -553,6 +604,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
         * @see TS_links_rte()
         */
        function TS_links_db($value) {
+               $conf = array();
 
                        // Split content into <a> tag blocks and process:
                $blockSplit = $this->splitIntoBlock('A', $value);
@@ -584,14 +636,14 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                $attribArray_copy = $processor->removeParams( $parameters, $this);
                                        }
                                }
-
-                               if (!count($attribArray_copy)) { // Only if href, target and class are the only attributes, we can alter the link!
+                                       // Only if href, target, class and tile are the only attributes, we can alter the link!
+                               if (!count($attribArray_copy)) {
                                                // Quoting class and title attributes if they contain spaces
                                        $attribArray['class'] = preg_match('/ /', $attribArray['class']) ? '"' . $attribArray['class'] . '"' : $attribArray['class'];
                                        $attribArray['title'] = preg_match('/ /', $attribArray['title']) ? '"' . $attribArray['title'] . '"' : $attribArray['title'];
                                                // Creating the TYPO3 pseudo-tag "<LINK>" for the link (includes href/url, target and class attributes):
                                                // If data-htmlarea-external attribute is set, keep the href unchanged
-                                       $href = $attribArray['data-htmlarea-external'] ? $attribArray['href'] : $info['url'] . ($info['query'] ? ',0,' . $info['query'] : '');
+                                       $href = ($attribArray['data-htmlarea-external'] ? $attribArray['href'] : $info['url']) . ($info['query'] ? ',0,' . $info['query'] : '');
                                        $bTag = '<link ' . $href . ($attribArray['target'] ? ' ' . $attribArray['target'] : (($attribArray['class'] || $attribArray['title']) ? ' -' : '')) . ($attribArray['class'] ? ' ' . $attribArray['class'] : ($attribArray['title'] ? ' -' : '')) . ($attribArray['title'] ? ' ' . $attribArray['title'] : '') . '>';
                                        $eTag = '</link>';
 
@@ -639,6 +691,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
         * @see TS_links_rte()
         */
        function TS_links_rte($value) {
+               $conf = array();
                $value = $this->TS_AtagToAbs($value);
 
                        // Split content by the TYPO3 pseudo tag "<link>":
@@ -646,6 +699,7 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                $siteUrl = $this->siteUrl();
                foreach ($blockSplit as $k => $v) {
                        $error = '';
+                       $external = FALSE;
                        if ($k % 2) { // block:
                                $tagCode = t3lib_div::unQuoteFilenames(trim(substr($this->getFirstTag($v), 0, -1)), TRUE);
                                $link_param = $tagCode[1];
@@ -656,50 +710,55 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                } elseif (substr($link_param, 0, 1) == '#') { // check if anchor
                                        $href = $siteUrl . $link_param;
                                } else {
-                                       $fileChar = intval(strpos($link_param, '/'));
-                                       $urlChar = intval(strpos($link_param, '.'));
-                                       $external = FALSE;
-                                               // Parse URL:
-                                       $pU = parse_url($link_param);
-                                               // Detects if a file is found in site-root.
-                                       list($rootFileDat) = explode('?', $link_param);
-                                       $rFD_fI = pathinfo($rootFileDat);
-                                       if (trim($rootFileDat) && !strstr($link_param, '/') && (@is_file(PATH_site . $rootFileDat) || t3lib_div::inList('php,html,htm', strtolower($rFD_fI['extension'])))) {
-                                               $href = $siteUrl . $link_param;
-                                       } elseif ($pU['scheme'] || ($urlChar && (!$fileChar || $urlChar < $fileChar))) {
-                                                       // url (external): if has scheme or if a '.' comes before a '/'.
-                                               $href = $link_param;
-                                               if (!$pU['scheme']) {
-                                                       $href = 'http://' . $href;
-                                               }
-                                               $external = TRUE;
-                                       } elseif ($fileChar) { // file (internal)
-                                               $href = $siteUrl . $link_param;
-                                       } else { // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
-                                                       // Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/parameters triplet
-                                               $pairParts = t3lib_div::trimExplode(',', $link_param, TRUE);
-                                               $idPart = $pairParts[0];
-                                               $link_params_parts = explode('#', $idPart);
-                                               $idPart = trim($link_params_parts[0]);
-                                               $sectionMark = trim($link_params_parts[1]);
-                                               if (!strcmp($idPart, '')) {
-                                                       $idPart = $this->recPid;
-                                               } // If no id or alias is given, set it to class record pid
-                                                       // Checking if the id-parameter is an alias.
-                                               if (!t3lib_utility_Math::canBeInterpretedAsInteger($idPart)) {
-                                                       list($idPartR) = t3lib_BEfunc::getRecordsByField('pages', 'alias', $idPart);
-                                                       $idPart = intval($idPartR['uid']);
-                                               }
-                                               $page = t3lib_BEfunc::getRecord('pages', $idPart);
-                                               if (is_array($page)) { // Page must exist...
-                                                       $href = $siteUrl . '?id=' . $idPart . ($pairParts[2] ? $pairParts[2] : '') . ($sectionMark ? '#' . $sectionMark : '');
-                                                               // linkHandler - allowing links to start with registerd linkHandler e.g.. "record:"
-                                               } elseif (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][array_shift(explode(':', $link_param))])) {
+                                               // Check for FAL link-handler keyword:
+                                       list ($linkHandlerKeyword, $linkHandlerValue) = explode(':', trim($link_param), 2);
+                                       if ($linkHandlerKeyword === 'file') {
+                                               $href = $siteUrl . '?' . $linkHandlerKeyword . ':' . rawurlencode($linkHandlerValue);
+                                       } else {
+                                               $fileChar = intval(strpos($link_param, '/'));
+                                               $urlChar = intval(strpos($link_param, '.'));
+                                                       // Parse URL:
+                                               $pU = parse_url($link_param);
+                                                       // Detects if a file is found in site-root.
+                                               list($rootFileDat) = explode('?', $link_param);
+                                               $rFD_fI = pathinfo($rootFileDat);
+                                               if (trim($rootFileDat) && !strstr($link_param, '/') && (@is_file(PATH_site . $rootFileDat) || t3lib_div::inList('php,html,htm', strtolower($rFD_fI['extension'])))) {
+                                                       $href = $siteUrl . $link_param;
+                                               } elseif ($pU['scheme'] || ($urlChar && (!$fileChar || $urlChar < $fileChar))) {
+                                                               // url (external): if has scheme or if a '.' comes before a '/'.
                                                        $href = $link_param;
-                                               } else {
-                                                       #$href = '';
-                                                       $href = $siteUrl . '?id=' . $link_param;
-                                                       $error = 'No page found: ' . $idPart;
+                                                       if (!$pU['scheme']) {
+                                                               $href = 'http://' . $href;
+                                                       }
+                                                       $external = TRUE;
+                                               } elseif ($fileChar) { // file (internal)
+                                                       $href = $siteUrl . $link_param;
+                                               } else { // integer or alias (alias is without slashes or periods or commas, that is 'nospace,alphanum_x,lower,unique' according to tables.php!!)
+                                                               // Splitting the parameter by ',' and if the array counts more than 1 element it's a id/type/parameters triplet
+                                                       $pairParts = t3lib_div::trimExplode(',', $link_param, TRUE);
+                                                       $idPart = $pairParts[0];
+                                                       $link_params_parts = explode('#', $idPart);
+                                                       $idPart = trim($link_params_parts[0]);
+                                                       $sectionMark = trim($link_params_parts[1]);
+                                                       if (!strcmp($idPart, '')) {
+                                                               $idPart = $this->recPid;
+                                                       } // If no id or alias is given, set it to class record pid
+                                                               // Checking if the id-parameter is an alias.
+                                                       if (!t3lib_utility_Math::canBeInterpretedAsInteger($idPart)) {
+                                                               list($idPartR) = t3lib_BEfunc::getRecordsByField('pages', 'alias', $idPart);
+                                                               $idPart = intval($idPartR['uid']);
+                                                       }
+                                                       $page = t3lib_BEfunc::getRecord('pages', $idPart);
+                                                       if (is_array($page)) { // Page must exist...
+                                                               $href = $siteUrl . '?id=' . $idPart . ($pairParts[2] ? $pairParts[2] : '') . ($sectionMark ? '#' . $sectionMark : '');
+                                                                       // linkHandler - allowing links to start with registerd linkHandler e.g.. "record:"
+                                                       } elseif (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler'][array_shift(explode(':', $link_param))])) {
+                                                               $href = $link_param;
+                                                       } else {
+                                                               #$href = '';
+                                                               $href = $siteUrl . '?id=' . $link_param;
+                                                               $error = 'No page found: ' . $idPart;
+                                                       }
                                                }
                                        }
                                }
@@ -1563,8 +1622,12 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                if (substr(strtolower($url), 0, 7) == 'mailto:') {
                        $info['url'] = trim(substr($url, 7));
                        $info['type'] = 'email';
+                       // Is a FAL resource/identifier
+               } elseif (strpos($url, '?file:') !== FALSE) {
+                       $info['type'] = 'file';
+                       $info['url'] = rawurldecode(substr($url, strpos($url, '?file:') + 1));
                } else {
-                       $curURL = $this->siteUrl(); // 100502, removed this: 'http://'.t3lib_div::getThisUrl(); Reason: The url returned had typo3/ in the end - should be only the site's url as far as I see...
+                       $curURL = $this->siteUrl();
                        for ($a = 0; $a < strlen($url); $a++) {
                                if ($url{$a} != $curURL{$a}) {
                                        break;
index 5707d8e..e9bb79f 100644 (file)
@@ -61,7 +61,7 @@ t3lib_extMgm::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKE
 t3lib_extMgm::addUserTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/res/' . strtolower($TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['defaultConfiguration']) . '/userTSConfig.txt">');
 
        // Add Status Report about Conflicting Extensions
-require_once(t3lib_extMgm::extPath('rtehtmlarea') . 'hooks/statusreport/ext_localconf.php');
+require_once(t3lib_extMgm::extPath($_EXTKEY) . 'hooks/statusreport/ext_localconf.php');
 
        // Configure Lorem Ipsum hook to insert nonsense in wysiwyg mode
 if (t3lib_extMgm::isLoaded('lorem_ipsum') && (TYPO3_MODE == 'BE')) {
@@ -150,6 +150,7 @@ if ($TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['enableImages']) {
        $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['TYPO3Image']['objectReference'] = 'EXT:'.$_EXTKEY.'/extensions/TYPO3Image/class.tx_rtehtmlarea_typo3image.php:&tx_rtehtmlarea_typo3image';
        $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['TYPO3Image']['addIconsToSkin'] = 0;
        $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['plugins']['TYPO3Image']['disableInFE'] = 1;
+       require_once(t3lib_extMgm::extPath($_EXTKEY) . 'extensions/TYPO3Image/ext_localconf.php');
        if ($TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['defaultConfiguration'] == 'Advanced' || $TYPO3_CONF_VARS['EXTCONF'][$_EXTKEY]['defaultConfiguration'] == 'Typical') {
                t3lib_extMgm::addPageTSConfig('<INCLUDE_TYPOSCRIPT: source="FILE:EXT:' . $_EXTKEY . '/res/image/pageTSConfig.txt">');
        }
diff --git a/typo3/sysext/rtehtmlarea/extensions/TYPO3Image/ext_localconf.php b/typo3/sysext/rtehtmlarea/extensions/TYPO3Image/ext_localconf.php
new file mode 100644 (file)
index 0000000..8ad22c5
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+if (!defined ('TYPO3_MODE')) {
+       die('Access denied.');
+}
+
+// Extending TypoScript from static template uid=43 to set up parsing of custom file abstraction attributes on img tag
+t3lib_extMgm::addTypoScript($_EXTKEY, 'setup', '
+       #******************************************************
+       # Including library for processing of custom file abstraction attributes on img tag
+       #******************************************************
+       ##includeLibs.tx_rtehtmlarea_renderimgtag = EXT:rtehtmlarea/extensions/TYPO3Image/class.tx_rtehtmlarea_renderimgtag.php
+
+       lib.parseFunc_RTE {
+               ##tags.img = TEXT
+               ##tags.img {
+               ##      current = 1
+               ##      preUserFunc = tx_rtehtmlarea_renderimgtag->renderImgageAttributes
+               ##}
+               nonTypoTagStdWrap.HTMLparser.tags.img.fixAttrib {
+                       data-htmlarea-file-uid.unset = 1
+                       data-htmlarea-file-table.unset = 1
+               }
+       }
+', 43);
+
+?>
\ No newline at end of file
index a3131f9..296fc5b 100644 (file)
@@ -3,7 +3,7 @@
 *  Copyright notice
 *
 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
-*  (c) 2005-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2005-2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -55,7 +55,6 @@ class tx_rtehtmlarea_pageTree extends rtePageTree {
         * @return      string          HTML output.
         */
        function printTree($treeArr='') {
-               global $BACK_PATH;
                $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
                if (!is_array($treeArr))        $treeArr=$this->tree;
 
@@ -65,17 +64,17 @@ class tx_rtehtmlarea_pageTree extends rtePageTree {
                foreach($treeArr as $k => $v)   {
                        $c++;
                        $bgColorClass = ($c+1)%2 ? 'bgColor' : 'bgColor-10';
-                       if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='page' && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']==$v['row']['uid'] && $GLOBALS['SOBE']->browser->curUrlInfo['pageid'])       {
-                               $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
+                       if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='page' && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']==$v['row']['uid'] && $GLOBALS['SOBE']->browser->curUrlInfo['pageid']) {
+                               $arrCol = '<td><img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/blinkarrow_right.gif', 'width="5" height="9"') . ' class="c-blinkArrowR" alt="" /></td>';
                                $bgColorClass='bgColor4';
                        } else {
                                $arrCol='<td></td>';
                        }
 
                        $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&editorNo='.$GLOBALS['SOBE']->browser->editorNo.'&contentTypo3Language='.$GLOBALS['SOBE']->browser->contentTypo3Language.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandPage='.$v['row']['uid'].'\');';
-                       $cEbullet = $this->ext_isLinkable($v['row']['doktype'],$v['row']['uid']) ?
-                                               '<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/arrowbullet.gif','width="18" height="16"').' alt="" /></a>' :
-                                               '';
+                       $cEbullet = ($this->ext_isLinkable($v['row']['doktype'], $v['row']['uid'])
+                               ? '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '"><img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/ol/arrowbullet.gif', 'width="18" height="16"') . ' alt="" /></a>'
+                               : '');
                        $out.='
                                <tr class="'.$bgColorClass.'">
                                        <td nowrap="nowrap"'.($v['row']['_CSSCLASS'] ? ' class="'.$v['row']['_CSSCLASS'].'"' : '').'>'.
@@ -112,81 +111,41 @@ class tx_rtehtmlarea_folderTree extends rteFolderTree {
        /**
         * Wrapping the title in a link, if applicable.
         *
-        * @param       string          Title, ready for output.
-        * @param       array           The "record"
-        * @return      string          Wrapping title string.
+        * @param       string                  Title, ready for output.
+        * @param       t3lib_file_Folder       The "record"
+        * @return      string                  Wrapping title string.
         */
-       function wrapTitle($title,$v)   {
-               $title = htmlspecialchars($title);
-
-               if ($this->ext_isLinkable($v))  {
-                       $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&editorNo='.$GLOBALS['SOBE']->browser->editorNo.'&contentTypo3Language='.$GLOBALS['SOBE']->browser->contentTypo3Language.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['path']).'\');';
-                       return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
+       function wrapTitle ($title, t3lib_file_Folder $folderObject) {
+               if ($this->ext_isLinkable($folderObject)) {
+                       $aOnClick = 'return jumpToUrl(\'' . $this->thisScript .
+                               '?act=' . $GLOBALS['SOBE']->browser->act .
+                               '&mode=' . $GLOBALS['SOBE']->browser->mode .
+                               '&editorNo=' . $GLOBALS['SOBE']->browser->editorNo .
+                               '&contentTypo3Language=' . $GLOBALS['SOBE']->browser->contentTypo3Language .
+                               '&contentTypo3Charset=' . $GLOBALS['SOBE']->browser->contentTypo3Charset .
+                               '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '\');';
+                       return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>';
                } else {
-                       return '<span class="typo3-dimmed">'.$title.'</span>';
+                       return '<span class="typo3-dimmed">' . $title . '</span>';
                }
        }
 
        /**
-        * Create the folder navigation tree in HTML
+        * Wrap the plus/minus icon in a link
         *
-        * @param       mixed           Input tree array. If not array, then $this->tree is used.
-        * @return      string          HTML output of the tree.
+        * @param       string          HTML string to wrap, probably an image tag.
+        * @param       string          Command for 'PM' get var
+        * @return      string          Link-wrapped input string
+        * @access private
         */
-       function printTree($treeArr='') {
-               global $BACK_PATH;
-               $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
-
-               if (!is_array($treeArr))        $treeArr=$this->tree;
-
-               $out='';
-               $c=0;
-
-                       // Preparing the current-path string (if found in the listing we will see a red blinking arrow).
-               if (!$GLOBALS['SOBE']->browser->curUrlInfo['value'])    {
-                       $cmpPath='';
-               } elseif (substr(trim($GLOBALS['SOBE']->browser->curUrlInfo['info']),-1)!='/')  {
-                       $cmpPath=PATH_site.dirname($GLOBALS['SOBE']->browser->curUrlInfo['info']).'/';
+       public function PMiconATagWrap ($icon, $cmd, $isExpand = TRUE) {
+               if ($this->thisScript) {
+                       $js = htmlspecialchars('Tree.thisScript=\'' . $GLOBALS['BACK_PATH'] . 'ajax.php\',Tree.load(\'' . $cmd . '\', ' . intval($isExpand) . ', this);');
+                       return '<a class="pm" onclick="' . $js . '">' . $icon . '</a>';
                } else {
-                       $cmpPath=PATH_site.$GLOBALS['SOBE']->browser->curUrlInfo['info'];
+                       return $icon;
                }
-
-                       // Traverse rows for the tree and print them into table rows:
-               foreach($treeArr as $k => $v)   {
-                       $c++;
-                       $bgColorClass=($c+1)%2 ? 'bgColor' : 'bgColor-10';
-
-                               // Creating blinking arrow, if applicable:
-                       if ($GLOBALS['SOBE']->browser->curUrlInfo['act']=='file' && $cmpPath==$v['row']['path'])        {
-                               $arrCol='<td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" /></td>';
-                               $bgColorClass='bgColor4';
-                       } else {
-                               $arrCol='<td></td>';
-                       }
-                               // Create arrow-bullet for file listing (if folder path is linkable):
-                       $aOnClick = 'return jumpToUrl(\''.$this->thisScript.'?act='.$GLOBALS['SOBE']->browser->act.'&editorNo='.$GLOBALS['SOBE']->browser->editorNo.'&contentTypo3Language='.$GLOBALS['SOBE']->browser->contentTypo3Language.'&mode='.$GLOBALS['SOBE']->browser->mode.'&expandFolder='.rawurlencode($v['row']['path']).'\');';
-                       $cEbullet = $this->ext_isLinkable($v['row']) ? '<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/arrowbullet.gif','width="18" height="16"').' alt="" /></a>' : '';
-
-                               // Put table row with folder together:
-                       $out.='
-                               <tr class="'.$bgColorClass.'">
-                                       <td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd_cs($v['row']['title'],$titleLen),$v['row']).'</td>
-                                       '.$arrCol.'
-                                       <td>'.$cEbullet.'</td>
-                               </tr>';
-               }
-
-               $out='
-
-                       <!--
-                               Folder tree:
-                       -->
-                       <table border="0" cellpadding="0" cellspacing="0" id="typo3-tree">
-                               '.$out.'
-                       </table>';
-               return $out;
        }
-
 }
 
 /**
@@ -198,9 +157,9 @@ class tx_rtehtmlarea_folderTree extends rteFolderTree {
  */
 class tx_rtehtmlarea_browse_links extends browse_links {
 
-       var $editorNo;
-       var $contentTypo3Language;
-       var $contentTypo3Charset = 'utf-8';
+       public $editorNo;
+       public $contentTypo3Language;
+       public $contentTypo3Charset = 'utf-8';
        public $additionalAttributes = array();
        public $buttonConfig = array();
        public $RTEProperties = array();
@@ -222,25 +181,19 @@ class tx_rtehtmlarea_browse_links extends browse_links {
         * @return      void
         */
        function init() {
-
                $this->initVariables();
                $this->initConfiguration();
-
                        // Creating backend template object:
                $this->doc = t3lib_div::makeInstance('template');
                $this->doc->backPath = $GLOBALS['BACK_PATH'];
                        // Loading the Prototype library and browse_links.js
                $this->doc->getPageRenderer()->loadPrototype();
+               $this->doc->loadJavascriptLib('js/tree.js');
                $this->doc->loadJavascriptLib('js/browse_links.js');
                        // Adding context menu code
                $this->doc->getContextMenuCode();
-                       // Init fileProcessor
-               $this->fileProcessor = t3lib_div::makeInstance('t3lib_basicFileFunctions');
-               $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']);
-
                        // Initializing hooking browsers
                $this->initHookObjects('ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php');
-
                        // CurrentUrl - the current link url must be passed around if it exists
                $this->curUrlArray = t3lib_div::_GP('curUrl');
                if ($this->curUrlArray['all'])  {
@@ -248,19 +201,18 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        $this->curUrlArray['href'] = htmlspecialchars_decode($this->curUrlArray['href']);
                }
                        // Note: parseCurUrl will invoke the hooks
-               $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'],$this->siteURL);
+               $this->curUrlInfo = $this->parseCurUrl($this->curUrlArray['href'], $this->siteURL);
                if (isset($this->curUrlArray['data-htmlarea-external']) && $this->curUrlInfo['act'] != 'mail') {
                        $this->curUrlInfo['act'] = 'url';
                        $this->curUrlInfo['info'] = $this->curUrlArray['href'];
                }
                        // Determine nature of current url:
                $this->act = t3lib_div::_GP('act');
-               if (!$this->act)        {
-                       $this->act=$this->curUrlInfo['act'];
+               if (!$this->act) {
+                       $this->act = $this->curUrlInfo['act'];
                }
                        // Setting intial values for link attributes
                $this->initLinkAttributes();
-
                        // Add attributes to body tag. Note: getBodyTagAdditions will invoke the hooks
                $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
                        // Adding RTE JS code
@@ -274,8 +226,15 @@ class tx_rtehtmlarea_browse_links extends browse_links {
         */
        public function initVariables() {
 
+                       // Main GPvars:
+               $this->pointer           = t3lib_div::_GP('pointer');
+               $this->bparams           = t3lib_div::_GP('bparams');
+               $this->P                 = t3lib_div::_GP('P');
+               $this->expandPage        = t3lib_div::_GP('expandPage');
+               $this->expandFolder      = t3lib_div::_GP('expandFolder');
+               $this->PM                = t3lib_div::_GP('PM');
+
                        // Process bparams
-               $this->bparams = t3lib_div::_GP('bparams');
                $pArr = explode('|', $this->bparams);
                $pRteArr = explode(':', $pArr[1]);
                $this->editorNo = $pRteArr[0];
@@ -286,11 +245,6 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        $this->contentTypo3Language = t3lib_div::_GP('contentTypo3Language');
                        $this->RTEtsConfigParams = t3lib_div::_GP('RTEtsConfigParams');
                }
-               $this->pointer = t3lib_div::_GP('pointer');
-               $this->expandPage = t3lib_div::_GP('expandPage');
-               $this->expandFolder = t3lib_div::_GP('expandFolder');
-               $this->P = t3lib_div::_GP('P');
-               $this->PM = t3lib_div::_GP('PM');
                $pArr[1] = implode(':', array($this->editorNo, $this->contentTypo3Language, $this->contentTypo3Charset));
                $pArr[2] = $this->RTEtsConfigParams;
                $this->bparams = implode('|', $pArr);
@@ -345,9 +299,8 @@ class tx_rtehtmlarea_browse_links extends browse_links {
         * @return      void
         */
        protected function initHookObjects($hookKey) {
-               global $TYPO3_CONF_VARS;
-               if (is_array($TYPO3_CONF_VARS['SC_OPTIONS'][$hookKey]['browseLinksHook'])) {
-                       foreach ($TYPO3_CONF_VARS['SC_OPTIONS'][$hookKey]['browseLinksHook'] as $classData) {
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'])) {
+                       foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookKey]['browseLinksHook'] as $classData) {
                                $processObject = t3lib_div::getUserObj($classData);
                                if(!($processObject instanceof t3lib_browseLinksHook)) {
                                        throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195115652);
@@ -371,16 +324,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
 
                        // Processing the classes configuration
                $classSelected = array();
-                       // $this->thisConfig['classesAnchor'], $this->thisConfig['classesLinks'] and $this->thisConfig['classesAnchor.'] are deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8
-               if ($this->buttonConfig['properties.']['class.']['allowedClasses'] || $this->thisConfig['classesAnchor'] || $this->thisConfig['classesLinks']) {
+               if ($this->buttonConfig['properties.']['class.']['allowedClasses']) {
                        $this->setClass = $this->curUrlArray['class'];
                        $classesAnchorArray = t3lib_div::trimExplode(',', $this->buttonConfig['properties.']['class.']['allowedClasses'], 1);
-                       $classesAnchorArray = array_merge($classesAnchorArray, t3lib_div::trimExplode(',', $this->thisConfig['classesAnchor'], 1));
-                       if (!count($classesAnchorArray) && $this->thisConfig['classesLinks']) {
-                               $classesAnchorArray = t3lib_div::trimExplode(',', $this->thisConfig['classesLinks'], 1);
-                       }
                        $classesAnchorConfigArray = array();
-                       
                                // Collecting allowed classes and configured default values
                        $classesAnchor = array();
                        $classesAnchor['all'] = array();
@@ -391,12 +338,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                $classesAnchor['all'][] = $conf['class'];
                                                if (in_array($conf['type'], $this->anchorTypes)) {
                                                        $classesAnchor[$conf['type']][] = $conf['class'];
-                                                       if (($this->buttonConfig[$conf['type']. '.']['properties.']['class.']['default'] == $conf['class'])
-                                                               || (!isset($this->buttonConfig[$conf['type']. '.']['properties.']['class.']['default'])
-                                                                       && $this->thisConfig['classesAnchor.']['default.'][$conf['type']] == $conf['class'])
-                                                               || (!isset($this->buttonConfig[$conf['type']. '.']['properties.']['class.']['default'])
-                                                                       && !isset($this->thisConfig['classesAnchor.']['default.'][$conf['type']])
-                                                                       && $this->buttonConfig['properties.']['class.']['default'] == $conf['class'])) {
+                                                       if ($this->buttonConfig[$conf['type']. '.']['properties.']['class.']['default'] == $conf['class']) {
                                                                $this->classesAnchorDefault[$conf['type']] = $conf['class'];
                                                                if ($conf['titleText']) {
                                                                        $this->classesAnchorDefaultTitle[$conf['type']] = $this->getLLContent(trim($conf['titleText']));
@@ -436,8 +378,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        // Initializing the target value
                        // Unset the target if it is set to a value different than default and if no class is selected and the target field is not displayed
                        // In other words, do not forward the target if we changed tab and the target field is not displayed
-                       // Property $this->thisConfig['defaultLinkTarget'] is deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8
-               $this->defaultLinkTarget = isset($this->buttonConfig['properties.']['target.']['default']) ? $this->buttonConfig['properties.']['target.']['default'] : (isset($this->thisConfig['defaultLinkTarget']) ? $this->thisConfig['defaultLinkTarget'] : '');
+               $this->defaultLinkTarget = isset($this->buttonConfig['properties.']['target.']['default']) ? $this->buttonConfig['properties.']['target.']['default'] : '';
                $this->setTarget = '';
                if (isset($this->curUrlArray['target']) && !(
                                $this->curUrlArray['target'] != $this->defaultLinkTarget
@@ -482,7 +423,6 @@ class tx_rtehtmlarea_browse_links extends browse_links {
         * @return      string          the generated JS code
         */
        function getJSCode()    {
-               global $BACK_PATH;
                        // BEGIN accumulation of header JavaScript:
                $JScode = '';
                $JScode.= '
@@ -536,7 +476,11 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                return false;
                        }
                        function link_folder(folder) {
-                               var theLink = \''.$this->siteURL.'\'+folder;
+                               if (folder && folder.substr(0, 5) == "file:") {
+                                       var theLink = \'' . $this->siteURL . '?file:\' + encodeURIComponent(folder.substr(5));
+                               } else {
+                                       var theLink = \'' . $this->siteURL . '?\' + folder;
+                               }
                                if (document.ltargetform.anchor_title) browse_links_setTitle(document.ltargetform.anchor_title.value);
                                if (document.ltargetform.anchor_class) browse_links_setClass(document.ltargetform.anchor_class.value);
                                if (document.ltargetform.ltarget) browse_links_setTarget(document.ltargetform.ltarget.value);
@@ -621,28 +565,24 @@ class tx_rtehtmlarea_browse_links extends browse_links {
         * @param       boolean         If set, the "remove link" is not shown in the menu: Used for the "Select link" wizard which is used by the TCEforms
         * @return      string          Modified content variable.
         */
-       function main_rte($wiz=0)       {
-               global $LANG, $BACK_PATH;
+       function main_rte ($wiz=0) {
 
                        // Starting content:
-               $content=$this->doc->startPage($LANG->getLL('Insert/Modify Link',1));
+               $content=$this->doc->startPage($GLOBALS['LANG']->getLL('Insert/Modify Link',1));
 
-                       // Initializing the action value, possibly adding/removing values
-               $this->allowedItems = explode(',','page,file,url,mail,spec');
+                       // Default allowed values
+               $this->allowedItems = explode(',','page,file,folder,url,mail,spec');
 
                        // Calling hook for extra options
                foreach($this->hookObjects as $hookObject) {
                        $this->allowedItems = $hookObject->addAllowedItems($this->allowedItems);
                }
-
+                       // Removing items as per configuration
                if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
                        $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->buttonConfig['options.']['removeItems'],1));
-               } else {
-                               // This PageTSConfig property is deprecated as of TYPO3 4.6 and will be removed in TYPO3 4.8
-                       $this->allowedItems = array_diff($this->allowedItems,t3lib_div::trimExplode(',',$this->thisConfig['blindLinkOptions'],1));
                }
                reset($this->allowedItems);
-               if (!in_array($this->act,$this->allowedItems)) {
+               if (!in_array($this->act, $this->allowedItems)) {
                        $this->act = current($this->allowedItems);
                }
 
@@ -650,37 +590,43 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                $menuDef = array();
                if (!$wiz && $this->curUrlArray['href'])        {
                        $menuDef['removeLink']['isActive'] = $this->act=='removeLink';
-                       $menuDef['removeLink']['label'] = $LANG->getLL('removeLink',1);
+                       $menuDef['removeLink']['label'] = $GLOBALS['LANG']->getLL('removeLink',1);
                        $menuDef['removeLink']['url'] = '#';
                        $menuDef['removeLink']['addParams'] = 'onclick="plugin.unLink();return false;"';
                }
-               if (in_array('page',$this->allowedItems)) {
+               if (in_array('page', $this->allowedItems)) {
                        $menuDef['page']['isActive'] = $this->act=='page';
-                       $menuDef['page']['label'] = $LANG->getLL('page',1);
+                       $menuDef['page']['label'] = $GLOBALS['LANG']->getLL('page',1);
                        $menuDef['page']['url'] = '#';
                        $menuDef['page']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=page&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
                }
-               if (in_array('file',$this->allowedItems)){
+               if (in_array('file', $this->allowedItems)){
                        $menuDef['file']['isActive'] = $this->act=='file';
-                       $menuDef['file']['label'] = $LANG->getLL('file',1);
+                       $menuDef['file']['label'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:file', 1);
                        $menuDef['file']['url'] = '#';
                        $menuDef['file']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=file&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
                }
-               if (in_array('url',$this->allowedItems)) {
+               if (in_array('folder', $this->allowedItems)){
+                       $menuDef['folder']['isActive'] = $this->act == 'folder';
+                       $menuDef['folder']['label'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_browse_links.xlf:folder', 1);
+                       $menuDef['folder']['url'] = '#';
+                       $menuDef['folder']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=folder&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
+               }
+               if (in_array('url', $this->allowedItems)) {
                        $menuDef['url']['isActive'] = $this->act=='url';
-                       $menuDef['url']['label'] = $LANG->getLL('extUrl',1);
+                       $menuDef['url']['label'] = $GLOBALS['LANG']->getLL('extUrl',1);
                        $menuDef['url']['url'] = '#';
                        $menuDef['url']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=url&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
                }
-               if (in_array('mail',$this->allowedItems)) {
+               if (in_array('mail', $this->allowedItems)) {
                        $menuDef['mail']['isActive'] = $this->act=='mail';
-                       $menuDef['mail']['label'] = $LANG->getLL('email',1);
+                       $menuDef['mail']['label'] = $GLOBALS['LANG']->getLL('email',1);
                        $menuDef['mail']['url'] = '#';
                        $menuDef['mail']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=mail&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
                }
-               if (is_array($this->thisConfig['userLinks.']) && in_array('spec',$this->allowedItems)) {
+               if (is_array($this->thisConfig['userLinks.']) && in_array('spec', $this->allowedItems)) {
                        $menuDef['spec']['isActive'] = $this->act=='spec';
-                       $menuDef['spec']['label'] = $LANG->getLL('special',1);
+                       $menuDef['spec']['label'] = $GLOBALS['LANG']->getLL('special',1);
                        $menuDef['spec']['url'] = '#';
                        $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\''.htmlspecialchars('?act=spec&mode='.$this->mode.'&bparams='.$this->bparams).'\');return false;"';
                }
@@ -693,10 +639,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                $content .= $this->doc->getTabMenuRaw($menuDef);
 
                        // Adding the menu and header to the top of page:
-               $content.=$this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
+               $content .= $this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
 
                        // Depending on the current action we will create the actual module content for selecting a link:
-               switch($this->act)      {
+               switch ($this->act) {
                        case 'mail':
                                $extUrl='
                        <!--
@@ -705,14 +651,14 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                        <form action="" name="lurlform" id="lurlform">
                                                <table border="0" cellpadding="2" cellspacing="1" id="typo3-linkMail">
                                                        <tr>
-                                                               <td>'.$LANG->getLL('emailAddress',1).':</td>
+                                                               <td>' . $GLOBALS['LANG']->getLL('emailAddress',1).':</td>
                                                                <td><input type="text" name="lemail"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='mail'?$this->curUrlInfo['info']:'').'" /> '.
-                                                                       '<input type="submit" value="'.$LANG->getLL('setLink',1).'" onclick="browse_links_setTarget(\'\');browse_links_setHref(\'mailto:\'+document.lurlform.lemail.value);browse_links_setAdditionalValue(\'data-htmlarea-external\', \'\');return link_current();" /></td>
+                                                                       '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink',1).'" onclick="browse_links_setTarget(\'\');browse_links_setHref(\'mailto:\'+document.lurlform.lemail.value);browse_links_setAdditionalValue(\'data-htmlarea-external\', \'\');return link_current();" /></td>
                                                        </tr>
                                                </table>
                                        </form>';
-                               $content.=$extUrl;
-                               $content.=$this->addAttributesForm();
+                               $content .= $extUrl;
+                               $content .= $this->addAttributesForm();
                        break;
                        case 'url':
                                $extUrl='
@@ -724,63 +670,94 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                        <tr>
                                                                <td>URL:</td>
                                                                <td><input type="text" name="lurl"'.$this->doc->formWidth(20).' value="'.htmlspecialchars($this->curUrlInfo['act']=='url'?$this->curUrlInfo['info']:'http://').'" /> '.
-                                                                       '<input type="submit" value="'.$LANG->getLL('setLink',1).'" onclick="if (/^[A-Za-z0-9_+]{1,8}:/.test(document.lurlform.lurl.value)) { browse_links_setHref(document.lurlform.lurl.value); } else { browse_links_setHref(\'http://\'+document.lurlform.lurl.value); }; browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); return link_current();" /></td>
+                                                                       '<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink',1).'" onclick="if (/^[A-Za-z0-9_+]{1,8}:/.test(document.lurlform.lurl.value)) { browse_links_setHref(document.lurlform.lurl.value); } else { browse_links_setHref(\'http://\'+document.lurlform.lurl.value); }; browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); return link_current();" /></td>
                                                        </tr>
                                                </table>
                                        </form>';
-                               $content.=$extUrl;
-                               $content.=$this->addAttributesForm();
+                               $content .= $extUrl;
+                               $content .= $this->addAttributesForm();
                        break;
                        case 'file':
-                               $content.=$this->addAttributesForm();
-
-                               $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_folderTree');
-                               $tree=$foldertree->getBrowsableTree();
-
-                               if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act']!='file')    {
-                                       $cmpPath='';
-                               } elseif (substr(trim($this->curUrlInfo['info']),-1)!='/')      {
-                                       $cmpPath=PATH_site.dirname($this->curUrlInfo['info']).'/';
-                                       if (!isset($this->expandFolder)) $this->expandFolder = $cmpPath;
+                       case 'folder':
+                               $content .= $this->addAttributesForm();
+
+                                       // Create folder tree:
+                               $this->doc->JScode .= $this->doc->wrapScriptTags('
+                                       Tree.ajaxID = "SC_alt_file_navframe::expandCollapse";
+                               ');
+                               $foldertree             = t3lib_div::makeInstance('tx_rtehtmlarea_folderTree');
+                               $foldertree->thisScript = $this->thisScript;
+                               $tree                   = $foldertree->getBrowsableTree();
+
+                               if (!$this->curUrlInfo['value'] || $this->curUrlInfo['act'] != $this->act) {
+                                       $cmpPath = '';
                                } else {
-                                       $cmpPath=PATH_site.$this->curUrlInfo['info'];
-                               }
-
-                               list(,,$specUid) = explode('_',$this->PM);
-                               $files = $this->expandFolder($foldertree->specUIDmap[$specUid]);
-
-                                       // Create upload/create folder forms, if a path is given:
-                               if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
-                                       $path=$this->expandFolder;
-                                       if (!$path || !@is_dir($path))  {
-                                               $path = $this->fileProcessor->findTempFolder().'/';     // The closest TEMP-path is found
+                                       $cmpPath = $this->curUrlInfo['value'];
+                                       if (!isset($this->expandFolder)) {
+                                               $this->expandFolder = $cmpPath;
                                        }
-                                       if ($path!='/' && @is_dir($path)) {
-                                               $uploadForm=$this->uploadForm($path);
-                                               $createFolder=$this->createFolder($path);
-                                       } else {
-                                               $createFolder='';
-                                               $uploadForm='';
+                               }
+                               if ($this->expandFolder) {
+                                       $selectedFolder = FALSE;
+
+                                       $fileOrFolderObject = t3lib_file_Factory::getInstance()->retrieveFileOrFolderObject($this->expandFolder);
+                                               // it's a file
+                                       if ($fileOrFolderObject instanceof t3lib_file_Folder) {
+                                               $selectedFolder = $fileOrFolderObject;
+
+                                       } elseif ($fileOrFolderObject instanceof t3lib_file_FileInterface) {
+                                               // @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);
                                        }
-                                       $content.=$uploadForm;
+                               }
+                                       // Add upload form if allowed
+                               if (!$selectedFolder) {
+                                       $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
+                                       $fileStorage = reset($fileStorages);
+                                       $selectedFolder = $fileStorage->getRootLevelFolder();
+                               }
+                               if ($selectedFolder) {
+                                       $uploadForm = ($this->act === 'file') ? $this->uploadForm($selectedFolder) : '';
+                                       $createFolder = $this->createFolder($selectedFolder);
+                               } else {
+                                       $uploadForm = $createFolder = '';
+                               }
+                               if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
+                                       $content .= $uploadForm;
                                        if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
-                                               $content.=$createFolder;
+                                               $content .= $createFolder;
                                        }
                                }
+                                       // Render the filelist if there is a folder selected
+                               if ($selectedFolder) {
+                                       $files = $this->expandFolder(
+                                               $selectedFolder,
+                                               $this->P['params']['allowedExtensions']
+                                       );
+                               }
 
+                               $content .= '
 
-
-                               $content.= '
                        <!--
-                       Wrapper table for folder tree / file list:
+                               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($LANG->getLL('folderTree').':').$tree.'</td>
-                                                       <td class="c-wCell" valign="top">'.$files.'</td>
+                                                       <td class="c-wCell" valign="top">' . $this->barheader($GLOBALS['LANG']->getLL('folderTree') . ':') . $tree . '</td>
+                                                       <td class="c-wCell" valign="top">' . $files . '</td>
                                                </tr>
                                        </table>
                                        ';
+
+                                       // Adding create folder + upload forms if applicable:
+                               if (!$GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
+                                       $content .= $uploadForm;
+                                       if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
+                                               $content .= $createFolder;
+                                       }
+                               }
                        break;
                        case 'spec':
                                if (is_array($this->thisConfig['userLinks.']))  {
@@ -795,10 +772,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                        if (!$title)    {
                                                                $title=$v[$k2i.'.']['url'];
                                                        } else {
-                                                               $title=$LANG->sL($title);
+                                                               $title=$GLOBALS['LANG']->sL($title);
                                                        }
                                                                // Description:
-                                                       $description=$v[$k2i.'.']['description'] ? $LANG->sL($v[$k2i.'.']['description'],1).'<br />' : '';
+                                                       $description=$v[$k2i.'.']['description'] ? $GLOBALS['LANG']->sL($v[$k2i.'.']['description'],1).'<br />' : '';
 
                                                                // URL + onclick event:
                                                        $onClickEvent='';
@@ -816,7 +793,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                                // Adding link to menu of user defined links:
                                                        $subcats[$k2i]='
                                                                <tr>
-                                                                       <td class="bgColor4">'.$A[0].'<strong>'.htmlspecialchars($title).($this->curUrlInfo['info']==$v[$k2i.'.']['url']?'<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" />':'').'</strong><br />'.$description.$A[1].'</td>
+                                                                       <td class="bgColor4">'.$A[0].'<strong>'.htmlspecialchars($title).($this->curUrlInfo['info']==$v[$k2i.'.']['url']?'<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/blinkarrow_right.gif','width="5" height="9"').' class="c-blinkArrowR" alt="" />':'').'</strong><br />'.$description.$A[1].'</td>
                                                                </tr>';
                                                }
                                        }
@@ -831,7 +808,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        -->
                                                <table border="0" cellpadding="1" cellspacing="1" id="typo3-linkSpecial">
                                                        <tr>
-                                                               <td class="bgColor5" class="c-wCell" valign="top"><strong>'.$LANG->getLL('special',1).'</strong></td>
+                                                               <td class="bgColor5" class="c-wCell" valign="top"><strong>' . $GLOBALS['LANG']->getLL('special', 1) . '</strong></td>
                                                        </tr>
                                                        '.implode('',$subcats).'
                                                </table>
@@ -852,7 +829,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                // Outputting Temporary DB mount notice:
                                if (intval($GLOBALS['BE_USER']->getSessionData('pageTree_temporaryMountPoint')))        {
                                        $link = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => 0))) . '">' .
-                                                                               $LANG->sl('LLL:EXT:lang/locallang_core.xml:labels.temporaryDBmount', 1) .
+                                                                               $GLOBALS['LANG']->sl('LLL:EXT:lang/locallang_core.xml:labels.temporaryDBmount', 1) .
                                                                        '</a>';
                                        $flashMessage = t3lib_div::makeInstance(
                                                't3lib_FlashMessage',
@@ -869,7 +846,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        -->
                                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-linkPages">
                                                <tr>
-                                                       <td class="c-wCell" valign="top">' . $this->barheader($LANG->getLL('pageTree') . ':') . $dbmount . $tree . '</td>
+                                                       <td class="c-wCell" valign="top">' . $this->barheader($GLOBALS['LANG']->getLL('pageTree') . ':') . $dbmount . $tree . '</td>
                                                        <td class="c-wCell" valign="top">' . $cElements . '</td>
                                                </tr>
                                        </table>
@@ -892,6 +869,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
 
        function addAttributesForm() {
                $ltargetForm = '';
+               $additionalAttributeFields = '';
                        // Add page id, target, class selector box, title and parameters fields:
                $lpageId = $this->addPageIdSelector();
                $queryParameters = $this->addQueryParametersSelector();
@@ -918,7 +896,6 @@ class tx_rtehtmlarea_browse_links extends browse_links {
        }
 
        function wrapInForm($string) {
-               global $LANG;
 
                $form = '
                        <!--
@@ -932,7 +909,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                        <td>
                                                        </td>
                                                        <td colspan="3">
-                                                               <input type="submit" value="'.$LANG->getLL('update',1).'" onclick="' . (($this->act == 'url') ? 'browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); ' : '') .'return link_current();" />
+                                                               <input type="submit" value="' . $GLOBALS['LANG']->getLL('update',1) . '" onclick="' . (($this->act == 'url') ? 'browse_links_setAdditionalValue(\'data-htmlarea-external\', \'1\'); ' : '') . 'return link_current();" />
                                                        </td>
                                                </tr>';
                }
@@ -943,13 +920,12 @@ class tx_rtehtmlarea_browse_links extends browse_links {
        }
 
        function addPageIdSelector() {
-               global $LANG;
 
                return ($this->act == 'page' && $this->buttonConfig && is_array($this->buttonConfig['pageIdSelector.']) && $this->buttonConfig['pageIdSelector.']['enabled'])?'
                                                <tr>
-                                                       <td>'.$LANG->getLL('page_id',1).':</td>
+                                                       <td>' . $GLOBALS['LANG']->getLL('page_id',1) . ':</td>
                                                        <td colspan="3">
-                                                               <input type="text" size="6" name="luid" />&nbsp;<input type="submit" value="'.$LANG->getLL('setLink',1).'" onclick="return link_typo3Page(document.ltargetform.luid.value);" />
+                                                               <input type="text" size="6" name="luid" />&nbsp;<input type="submit" value="' . $GLOBALS['LANG']->getLL('setLink', 1) . '" onclick="return link_typo3Page(document.ltargetform.luid.value);" />
                                                        </td>
                                                </tr>':'';
        }
@@ -965,11 +941,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
        }
 
        function addQueryParametersSelector() {
-               global $LANG;
 
                return ($this->act == 'page' && $this->buttonConfig && is_array($this->buttonConfig['queryParametersSelector.']) && $this->buttonConfig['queryParametersSelector.']['enabled'])?'
                                                <tr>
-                                                       <td>'.$LANG->getLL('query_parameters',1).':</td>
+                                                       <td>' . $GLOBALS['LANG']->getLL('query_parameters', 1) . ':</td>
                                                        <td colspan="3">
                                                                <input type="text" name="query_parameters" value="' . ($this->curUrlInfo['query']?$this->curUrlInfo['query']:'') . '" ' . $this->doc->formWidth(30) . ' />
                                                        </td>
@@ -977,7 +952,6 @@ class tx_rtehtmlarea_browse_links extends browse_links {
        }
 
        function addTargetSelector() {
-               global $LANG;
 
                $targetSelectorConfig = array();
                $popupSelectorConfig = array();
@@ -992,7 +966,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                if ($this->act != 'mail')       {
                        $ltarget .= '
                                        <tr id="ltargetrow"'. (($targetSelectorConfig['disabled'] && $popupSelectorConfig['disabled']) ? ' style="display: none;"' : '') . '>
-                                               <td>'.$LANG->getLL('target',1).':</td>
+                                               <td>' . $GLOBALS['LANG']->getLL('target', 1) . ':</td>
                                                <td><input type="text" name="ltarget" onchange="browse_links_setTarget(this.value);" value="'.htmlspecialchars($this->setTarget?$this->setTarget:(($this->setClass || !$this->classesAnchorDefault[$this->act])?'':$this->classesAnchorDefaultTarget[$this->act])).'"'.$this->doc->formWidth(10).' /></td>';
                        $ltarget .= '
                                                <td colspan="2">';
@@ -1000,8 +974,8 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                $ltarget .= '
                                                        <select name="ltarget_type" onchange="browse_links_setTarget(this.options[this.selectedIndex].value);document.ltargetform.ltarget.value=this.options[this.selectedIndex].value;this.selectedIndex=0;">
                                                                <option></option>
-                                                               <option value="_top">'.$LANG->getLL('top',1).'</option>
-                                                               <option value="_blank">'.$LANG->getLL('newWindow',1).'</option>
+                                                               <option value="_top">' . $GLOBALS['LANG']->getLL('top', 1) . '</option>
+                                                               <option value="_blank">' . $GLOBALS['LANG']->getLL('newWindow', 1) . '</option>
                                                        </select>';
                        }
                        $ltarget .= '
@@ -1018,10 +992,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
 
                                $ltarget.='
                                                <tr>
-                                                       <td>'.$LANG->getLL('target_popUpWindow',1).':</td>
+                                                       <td>' . $GLOBALS['LANG']->getLL('target_popUpWindow', 1) . ':</td>
                                                        <td colspan="3">
                                                                <select name="popup_width" onchange="'.$selectJS.'">
-                                                                       <option value="0">'.$LANG->getLL('target_popUpWindow_width',1).'</option>
+                                                                       <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_width', 1) . '</option>
                                                                        <option value="300">300</option>
                                                                        <option value="400">400</option>
                                                                        <option value="500">500</option>
@@ -1031,7 +1005,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                                </select>
                                                                x
                                                                <select name="popup_height" onchange="'.$selectJS.'">
-                                                                       <option value="0">'.$LANG->getLL('target_popUpWindow_height',1).'</option>
+                                                                       <option value="0">' . $GLOBALS['LANG']->getLL('target_popUpWindow_height', 1) . '</option>
                                                                        <option value="200">200</option>
                                                                        <option value="300">300</option>
                                                                        <option value="400">400</option>
@@ -1144,21 +1118,17 @@ class tx_rtehtmlarea_browse_links extends browse_links {
         * @return      string          Localized string.
         */
        public function getPageConfigLabel($string,$JScharCode=1) {
-               global $LANG;
                if (strcmp(substr($string,0,4),'LLL:')) {
                        $label = $string;
                } else {
-                       $label = $LANG->sL(trim($string));
+                       $label = $GLOBALS['LANG']->sL(trim($string));
                }
                $label = str_replace('"', '\"', str_replace('\\\'', '\'', $label));
-               $label = $JScharCode ? $LANG->JScharCode($label): $label;
+               $label = $JScharCode ? $GLOBALS['LANG']->JScharCode($label): $label;
                return $label;
        }
-
 }
-
 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php'])) {
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php']);
 }
-
 ?>
index 22ca70c..b8d093c 100644 (file)
@@ -3,7 +3,7 @@
 *  Copyright notice
 *
 *  (c) 1999-2011 Kasper Skårhøj (kasper@typo3.com)
-*  (c) 2004-2011 Stanislas Rolland <typo3(arobas)sjbr.ca>
+*  (c) 2004-2012 Stanislas Rolland <typo3(arobas)sjbr.ca>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -31,7 +31,8 @@
  * @author     Kasper Skårhøj <kasper@typo3.com>
  * @author     Stanislas Rolland <typo3(arobas)sjbr.ca>
  */
-require_once(PATH_typo3.'class.browse_links.php');
+require_once(PATH_typo3 . 'class.browse_links.php');
+require_once(PATH_t3lib . 'file/Service/MagicImageService.php');
 
 /**
  * Local Folder Tree
@@ -40,41 +41,38 @@ require_once(PATH_typo3.'class.browse_links.php');
  * @package TYPO3
  * @subpackage tx_rte
  */
-class tx_rtehtmlarea_image_folderTree extends t3lib_folderTree {
-       var $ext_IconMode=1;
+class tx_rtehtmlarea_image_folderTree extends TBE_FolderTree {
+       var $ext_IconMode = 1;
 
        /**
         * Wrapping the title in a link, if applicable.
         *
-        * @param       string          Title, ready for output.
-        * @param       array           The "record"
-        * @return      string          Wrapping title string.
+        * @param       string                  Title, ready for output.
+        * @param       t3lib_file_Folder       The "record"
+        * @return      string                  Wrapping title string.
         */
-       function wrapTitle($title,$v)   {
-               $title = htmlspecialchars($title);
-
-               if ($this->ext_isLinkable($v))  {
-                       $aOnClick = 'return jumpToUrl(\'?editorNo='.$GLOBALS['SOBE']->browser->editorNo.'&expandFolder='.rawurlencode($v['path']).'\');';
-                       return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
+       function wrapTitle($title, t3lib_file_Folder $folderObject) {
+               if ($this->ext_isLinkable($folderObject)) {
+                       $aOnClick = 'return jumpToUrl(\'' . $this->thisScript .
+                               '?editorNo=' . $GLOBALS['SOBE']->browser->editorNo .
+                               '&act=' . $GLOBALS['SOBE']->browser->act . 
+                               '&mode=' . $GLOBALS['SOBE']->browser->mode .
+                               '&expandFolder=' . rawurlencode($folderObject->getCombinedIdentifier()) . '\');';
+                       return '<a href="#" onclick="' . htmlspecialchars($aOnClick) . '">' . $title . '</a>';
                } else {
-                       return '<span class="typo3-dimmed">'.$title.'</span>';
+                       return '<span class="typo3-dimmed">' . $title . '</span>';
                }
        }
 
        /**
         * Returns TRUE if the input "record" contains a folder which can be linked.
         *
-        * @param       array           Array with information about the folder element. Contains keys like title, uid, path, _title
-        * @return      boolean         TRUE is returned if the path is found in the web-part of the the server and is NOT a recycler or temp folder
+        * @param       t3lib_file_Folder       Object with information about the folder element. Contains keys like title, uid, path, _title
+        * @return      boolean                 TRUE is returned if the path is found in the web-part of the the server and is NOT a recycler or temp folder
         */
-       function ext_isLinkable($v)     {
-               $webpath=t3lib_BEfunc::getPathType_web_nonweb($v['path']);
-               if ($GLOBALS['SOBE']->browser->act=='magic') return 1;  //$webpath='web';       // The web/non-web path does not matter if the mode is 'magic'
-
-               if (strstr($v['path'],'_recycler_') || strstr($v['path'],'_temp_') || $webpath!='web')  {
-                       return 0;
-               }
-               return 1;
+       function ext_isLinkable(t3lib_file_Folder $folderObject) {
+                       // $folderObject->getStorage()->isPublic() does not matter if the mode is 'magic'
+               return ($GLOBALS['SOBE']->browser->act === 'magic') || parent::ext_isLinkable($folderObject);
        }
 
        /**
@@ -82,42 +80,16 @@ class tx_rtehtmlarea_image_folderTree extends t3lib_folderTree {
         *
         * @param       string          HTML string to wrap, probably an image tag.
         * @param       string          Command for 'PM' get var
-        * @param       boolean         If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
         * @return      string          Link-wrapped input string
         * @access private
         */
-       function PM_ATagWrap($icon,$cmd,$bMark='')      {
-               if ($bMark)     {
-                       $anchor = '#'.$bMark;
-                       $name=' name="'.$bMark.'"';
-               }
-               $aOnClick = 'return jumpToUrl(\'?PM='.$cmd.'\',\''.$anchor.'\');';
-               return '<a href="#"'.$name.' onclick="'.htmlspecialchars($aOnClick).'">'.$icon.'</a>';
-       }
-
-       /**
-        * Print tree.
-        *
-        * @param       mixed           Input tree array. If not array, then $this->tree is used.
-        * @return      string          HTML output of the tree.
-        */
-       function printTree($treeArr='') {
-               $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
-
-               if (!is_array($treeArr))        $treeArr=$this->tree;
-
-               $out='';
-               $c=0;
-
-                       // Traverse rows for the tree and print them into table rows:
-               foreach($treeArr as $k => $v) {
-                       $c++;
-                       $bgColor=' class="'.(($c+1)%2 ? 'bgColor' : 'bgColor-10').'"';
-                       $out.='<tr'.$bgColor.'><td nowrap="nowrap">'.$v['HTML'].$this->wrapTitle(t3lib_div::fixed_lgd_cs($v['row']['title'],$titleLen),$v['row']).'</td></tr>';
+       public function PMiconATagWrap($icon, $cmd, $isExpand = TRUE) {
+               if ($this->thisScript) {
+                       $js = htmlspecialchars('Tree.thisScript=\'' . $GLOBALS['BACK_PATH'] . 'ajax.php\';Tree.load(\'' . $cmd . '\', ' . intval($isExpand) . ', this);');
+                       return '<a class="pm" onclick="' . $js . '">' . $icon . '</a>';
+               } else {
+                       return $icon;
                }
-
-               $out='<table border="0" cellpadding="0" cellspacing="0">'.$out.'</table>';
-               return $out;
        }
 }
 
@@ -155,8 +127,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      void
         */
-       function init() {
-               global $BACK_PATH;
+       function init() {
 
                $this->initVariables();
                $this->initConfiguration();
@@ -173,12 +144,15 @@ class tx_rtehtmlarea_select_image extends browse_links {
                        // Creating backend template object:
                $this->doc = t3lib_div::makeInstance('template');
                $this->doc->bodyTagAdditions = $this->getBodyTagAdditions();
-               $this->doc->backPath = $BACK_PATH;
+               $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();
        }
 
@@ -233,9 +207,8 @@ class tx_rtehtmlarea_select_image extends browse_links {
         * @return      void
         */
        protected function initHookObjects() {
-               global $TYPO3_CONF_VARS;
-               if (is_array($TYPO3_CONF_VARS['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'])) {
-                       foreach ($TYPO3_CONF_VARS['SC_OPTIONS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']['browseLinksHook'] as $classData) {
+               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 = t3lib_div::getUserObj($classData);
                                if(!($processObject instanceof t3lib_browseLinksHook)) {
                                        throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195115652);
@@ -261,7 +234,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      string          the path to the folder where RTE images are stored
         */
-       protected function getRTEImageStorageDir()      {
+       protected function getRTEImageStorageDir() {
                return ($this->imgPath ? $this->imgPath : $GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']);
        }
 
@@ -270,23 +243,25 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      void
         */
-       protected function insertImage()        {
-               if (t3lib_div::_GP('insertImage'))      {
-                       $filepath = t3lib_div::_GP('insertImage');
-                       $imgInfo = $this->getImageInfo($filepath);
+       protected function insertImage() {
+               if (t3lib_div::_GP('insertImage')) {
+                       $table = t3lib_div::_GP('table');
+                       $uid = t3lib_div::_GP('uid');
+                       $fileObject = t3lib_file_Factory::getInstance()->getFileObject($uid);
+
                        switch ($this->act) {
                                case 'magic':
-                                       $this->insertMagicImage($filepath, $imgInfo);
+                                       $this->insertMagicImage($fileObject, '', '', 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
                                        exit;
                                        break;
                                case 'plain':
-                                       $this->insertPlainImage($imgInfo);
+                                       $this->insertPlainImage($fileObject, '', '', 'data-htmlarea-file-uid="' . $uid . '" data-htmlarea-file-table="' . $table . '"');
                                        exit;
                                        break;
                                default:
                                                // Call hook
                                        foreach ($this->hookObjects as $hookObject) {
-                                               if (method_exists($hookObject, "insertElement")) {
+                                               if (method_exists($hookObject, 'insertElement')) {
                                                        $hookObject->insertElement($this->act);
                                                }
                                        }
@@ -296,84 +271,56 @@ class tx_rtehtmlarea_select_image extends browse_links {
        }
 
        /**
-        * Get the information on the image file identified its path
-        *
-        * @param       string          $filepath: the path to the image file
-        *
-        * @return      array           a 4-elements information array about the file
-        */
-       public function getImageInfo($filepath) {
-               $this->imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
-               $this->imgObj->init();
-               $this->imgObj->mayScaleUp = 0;
-               $this->imgObj->tempPath = PATH_site.$this->imgObj->tempPath;
-               return $this->imgObj->getImageDimensions($filepath);
-       }
-
-       /**
         * Insert a magic image
         *
-        * @param       string          $filepath: the path to the image file
-        * @param       array           $imgInfo: a 4-elements information array about the file
+        * @param t3lib_file_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
         */
-       public function insertMagicImage($filepath, $imgInfo, $altText='', $titleText='', $additionalParams='') {
-               if (is_array($imgInfo) && count($imgInfo) == 4) {
-                       if ($this->RTEImageStorageDir) {
-                               $fI = pathinfo($imgInfo[3]);
-                               $fileFunc = t3lib_div::makeInstance('t3lib_basicFileFunctions');
-                               $basename = $fileFunc->cleanFileName('RTEmagicP_'.$fI['basename']);
-                               $destPath =PATH_site.$this->RTEImageStorageDir;
-                               if (@is_dir($destPath)) {
-                                       $destName = $fileFunc->getUniqueName($basename,$destPath);
-                                       @copy($imgInfo[3],$destName);
-                                       t3lib_div::fixPermissions($destName);
-                                       $cWidth = t3lib_utility_Math::forceIntegerInRange(t3lib_div::_GP('cWidth'), 0, $this->magicMaxWidth);
-                                       $cHeight = t3lib_utility_Math::forceIntegerInRange(t3lib_div::_GP('cHeight'), 0, $this->magicMaxHeight);
-                                       if (!$cWidth)   $cWidth = $this->magicMaxWidth;
-                                       if (!$cHeight)  $cHeight = $this->magicMaxHeight;
-
-                                       $imgI = $this->imgObj->imageMagickConvert($filepath,'WEB',$cWidth.'m',$cHeight.'m');    // ($imagefile,$newExt,$w,$h,$params,$frame,$options,$mustCreate=0)
-                                       if ($imgI[3])   {
-                                               $fI=pathinfo($imgI[3]);
-                                               $mainBase='RTEmagicC_'.substr(basename($destName),10).'.'.$fI['extension'];
-                                               $destName = $fileFunc->getUniqueName($mainBase,$destPath);
-                                               @copy($imgI[3],$destName);
-                                               t3lib_div::fixPermissions($destName);
-                                               $destName = dirname($destName).'/'.rawurlencode(basename($destName));
-                                               $iurl = $this->siteURL.substr($destName,strlen(PATH_site));
-                                               $this->imageInsertJS($iurl, $imgI[0], $imgI[1], $altText, $titleText, $additionalParams);
-                                       } else {
-                                               t3lib_div::sysLog('Attempt at creating a magic image failed due to error converting image: "' . $filepath . '".', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
-                                       }
-                               } else {
-                                       t3lib_div::sysLog('Attempt at creating a magic image failed due to incorrect destination path: "' . $destPath . '".', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
-                               }
-                       } else {
-                               t3lib_div::sysLog('Attempt at creating a magic image failed due to absent RTE_imageStorageDir', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
+       public function insertMagicImage(t3lib_file_FileInterface $fileObject, $altText='', $titleText='', $additionalParams='') {
+               if ($this->RTEImageStorageDir) {
+                       /** @var $magicImageService t3lib_file_Service_MagicImageService */
+                       $magicImageService = t3lib_div::makeInstance('t3lib_file_Service_MagicImageService');
+                       $imageConfiguration = array(
+                               'width' => t3lib_div::_GP('cWidth'),
+                               'height' => t3lib_div::_GP('cHeight'),
+                               'maxW' => $this->magicMaxWidth,
+                               'maxH' => $this->magicMaxHeight,
+                       );
+
+                       $magicImage = $magicImageService->createMagicImage(
+                               $fileObject,
+                               $imageConfiguration,
+                               $this->getRTEImageStorageDir()
+                       );
+
+                       if ($magicImage instanceof t3lib_file_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 {
-                       t3lib_div::sysLog('Attempt at creating a magic image failed due to missing image file info.', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
+                       t3lib_div::sysLog('Attempt at creating a magic image failed due to absent RTE_imageStorageDir', $this->extKey . '/tx_rtehtmlarea_select_image', t3lib_div::SYSLOG_SEVERITY_ERROR);
                }
        }
 
        /**
         * Insert a plain image
         *
-        * @param       array           $imgInfo: a 4-elements information array about the file
+        * @param t3lib_file_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
         */
-       public function insertPlainImage($imgInfo, $altText='', $titleText='', $additionalParams='') {
-               if (is_array($imgInfo) && count($imgInfo)==4)   {
-                       $iurl = $this->siteURL.substr($imgInfo[3],strlen(PATH_site));
-                       $this->imageInsertJS($iurl, $imgInfo[0], $imgInfo[1], $altText, $titleText, $additionalParams);
-               }
+       public function insertPlainImage(t3lib_file_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);
        }
 
        /**
@@ -389,7 +336,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         */
        protected function imageInsertJS($url, $width, $height, $altText='', $titleText='', $additionalParams='') {
                echo'
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<!DOCTYPE html>
 <html>
 <head>
        <title>Untitled</title>
@@ -422,8 +369,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      string          the generated JS code
         */
-       function getJSCode($act, $editorNo, $sys_language_content)      {
-               global $LANG, $TYPO3_CONF_VARS;
+       function getJSCode($act, $editorNo, $sys_language_content) {
 
                $removedProperties = array();
                if (is_array($this->buttonConfig['properties.'])) {
@@ -457,6 +403,13 @@ class tx_rtehtmlarea_select_image extends browse_links {
                $JScode='
                        var plugin = window.parent.RTEarea["' . $editorNo . '"].editor.getPlugin("TYPO3Image");
                        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 . '\');
+                       }
+                       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 . '\');
+                       }
                        function initEventListeners() {
                                if (Ext.isWebKit) {
                                        Ext.EventManager.addListener(window.document.body, "dragend", plugin.onDrop, plugin, { single: true });
@@ -495,7 +448,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
                        function printCurrentImageOptions() {
                                var classesImage = ' . (($this->buttonConfig['properties.']['class.']['allowedClasses'] || $this->thisConfig['classesImage']) ? 'true' : 'false') . ';
                                if (classesImage) var styleSelector=\'<select id="iClass" name="iClass" style="width:140px;">' . $classesImageJSOptions  . '</select>\';
-                               var floatSelector=\'<select id="iFloat" name="iFloat"><option value="">' . $LANG->getLL('notSet') . '</option><option value="none">' . $LANG->getLL('nonFloating') . '</option><option value="left">' . $LANG->getLL('left') . '</option><option value="right">' . $LANG->getLL('right') . '</option></select>\';
+                               var floatSelector=\'<select id="iFloat" name="iFloat"><option value="">' . $GLOBALS['LANG']->getLL('notSet') . '</option><option value="none">' . $GLOBALS['LANG']->getLL('nonFloating') . '</option><option value="left">' . $GLOBALS['LANG']->getLL('left') . '</option><option value="right">' . $GLOBALS['LANG']->getLL('right') . '</option></select>\';
                                if (plugin.getButton("Language")) {
                                        var languageSelector = \'<select id="iLang" name="iLang">\';
                                        plugin.getButton("Language").getStore().each(function (record) {
@@ -508,39 +461,39 @@ class tx_rtehtmlarea_select_image extends browse_links {
                                sz+=\'<table border="0" cellpadding="1" cellspacing="1"><form action="" name="imageData">\';
                                '.(in_array('class', $removedProperties)?'':'
                                if(classesImage) {
-                                       sz+=\'<tr><td\'+bgColor+\'><label for="iClass">'.$LANG->getLL('class').': </label></td><td>\'+styleSelector+\'</td></tr>\';
+                                       sz+=\'<tr><td\'+bgColor+\'><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">'.$LANG->getLL('width').': </label></td><td><input type="text" id="iWidth" name="iWidth" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
+                                       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>\';
                                }')
                                .(in_array('height', $removedProperties)?'':'
                                if (!(selectedImageRef && selectedImageRef.src.indexOf("RTEmagic") == -1 && '. $lockPlainHeight .')) {
-                                       sz+=\'<tr><td\'+bgColor+\'><label for="iHeight">'.$LANG->getLL('height').': </label></td><td><input type="text" id="iHeight" name="iHeight" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';
+                                       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>\';
                                }')
                                .(in_array('border', $removedProperties)?'':'
-                               sz+=\'<tr><td\'+bgColor+\'><label for="iBorder">'.$LANG->getLL('border').': </label></td><td><input type="checkbox" id="iBorder" name="iBorder" value="1" /></td></tr>\';')
+                               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">'.$LANG->getLL('float').': </label></td><td>\'+floatSelector+\'</td></tr>\';')
+                               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">'.$LANG->getLL('padding_top').': </label></td><td><input type="text" id="iPaddingTop" name="iPaddingTop" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).'></td></tr>\';')
+                               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">'.$LANG->getLL('padding_right').': </label></td><td><input type="text" id="iPaddingRight" name="iPaddingRight" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';')
+                               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">'.$LANG->getLL('padding_bottom').': </label></td><td><input type="text" id="iPaddingBottom" name="iPaddingBottom" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';')
+                               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">'.$LANG->getLL('padding_left').': </label></td><td><input type="text" id="iPaddingLeft" name="iPaddingLeft" value=""'.$GLOBALS['TBE_TEMPLATE']->formWidth(4).' /></td></tr>\';')
+                               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">'.$LANG->getLL('title').': </label></td><td><input type="text" id="iTitle" name="iTitle"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' /></td></tr>\';')
+                               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">'.$LANG->getLL('alt').': </label></td><td><input type="text" id="iAlt" name="iAlt"'.$GLOBALS['TBE_TEMPLATE']->formWidth(20).' /></td></tr>\';')
+                               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)?'':'
                                if (plugin.getButton("Language")) {
                                        sz+=\'<tr><td\'+bgColor+\'><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">'.$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="'.$LANG->getLL('update').'" onClick="return setImageProperties();"></td></tr>\';
+                               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>\';
                                return sz;
                        }
@@ -782,7 +735,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      [type]          ...
         */
-       function main_rte()     {
+       function main_rte() {
                        // Starting content:
                $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('Insert Image',1));
 
@@ -830,7 +783,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
 
                $this->content .= $this->doc->getTabMenuRaw($menuDef);
 
-               switch($this->act)      {
+               switch ($this->act) {
                        case 'image':
                                $JScode = '
                                document.write(printCurrentImageOptions());
@@ -839,33 +792,57 @@ class tx_rtehtmlarea_select_image extends browse_links {
                                break;
                        case 'plain':
                        case 'magic':
-                                       // Adding upload form, if allowed
-                               $this->content .= $this->insertUploadForm($this->expandFolder);
-                                       // Getting flag for showing/not showing thumbnails:
-                               $noThumbs = $GLOBALS['BE_USER']->getTSConfigVal('options.noThumbsInRTEimageSelect');
-                               if (!$noThumbs) {
-                                               // MENU-ITEMS, fetching the setting for thumbnails from File>List module:
-                                       $_MOD_MENU = array('displayThumbs' => '');
-                                       $_MCONF['name']='file_list';
-                                       $_MOD_SETTINGS = t3lib_BEfunc::getModuleData($_MOD_MENU, t3lib_div::_GP('SET'), $_MCONF['name']);
-                                       $addParams = '&act='.$this->act.'&editorNo='.$this->editorNo.'&expandFolder='.rawurlencode($this->expandFolder);
-                                       $thumbNailCheck = t3lib_BEfunc::getFuncCheck('','SET[displayThumbs]',$_MOD_SETTINGS['displayThumbs'],'select_image.php',$addParams,'id="checkDisplayThumbs"').' <label for="checkDisplayThumbs">' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_mod_file_list.php:displayThumbs',1).'</label>';
-                               } else {
-                                       $thumbNailCheck='';
-                               }
                                        // Create folder tree:
                                $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_image_folderTree');
+                               $foldertree->thisScript = $this->thisScript;
                                $tree = $foldertree->getBrowsableTree();
-                               list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
-                               $files = $this->expandFolder($foldertree->specUIDmap[$specUid],$this->act=='plain',$noThumbs?$noThumbs:!$_MOD_SETTINGS['displayThumbs']);
-                               $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>
-                               <br />'.$thumbNailCheck;
+                                       // 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 = t3lib_file_Factory::getInstance()->getFolderObjectFromCombinedIdentifier(
+                                                       $this->expandFolder
+                                               );
+                                       } catch (Exception $e) {
+                                               $selectedFolder = FALSE;
+                                       }
+                               }
+                                       // Adding upload form, if allowed
+                               if ($selectedFolder) {
+                                       $this->content .= $this->insertUploadForm($selectedFolder);
+                               }
+
+                                       // 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) {
@@ -874,16 +851,38 @@ class tx_rtehtmlarea_select_image extends browse_links {
                                break;
                        case 'dragdrop':
                                $foldertree = t3lib_div::makeInstance('TBE_FolderTree');
-                               $foldertree->thisScript=$this->thisScript;
+                               $foldertree->thisScript = $this->thisScript;
                                $foldertree->ext_noTempRecyclerDirs = TRUE;
                                $tree = $foldertree->getBrowsableTree();
-                               list(,,$specUid) = explode('_',t3lib_div::_GP('PM'));
-                               $files = $this->TBE_dragNDrop($foldertree->specUIDmap[$specUid], implode(',', $this->allowedFileTypes));
-                               $this->content.= '<table border="0" cellpadding="0" cellspacing="0">
+                                       // 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 = t3lib_file_Factory::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 style="vertical-align: top;">' . $this->barheader($GLOBALS['LANG']->getLL('folderTree') . ':') . $tree . '</td>
                                        <td>&nbsp;</td>
-                                       <td style="vertical-align: top;">'.$files.'</td>
+                                       <td style="vertical-align: top;">' .$files. '</td>
                                </tr>
                                </table>';
                                break;
@@ -901,215 +900,34 @@ class tx_rtehtmlarea_select_image extends browse_links {
        }
 
        /**
-        * Create upload/create folder forms, if a path is given
+        * Create upload/create folder forms, if a folder is given
         *
-        * @param       string          $folderPath: the selected path , if any
-        *
-        * @return      string          the html content for the upload form
+        * @param t3lib_file_Folder $selectedFolder Absolute filepath on server to which to upload.
+        * @return string HTML for an upload form.
         */
-       protected function insertUploadForm($folderPath) {
+       protected function insertUploadForm(t3lib_file_Folder $selectedFolder) {
                $content = '';
-               if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB') && !$this->readOnly && count($GLOBALS['FILEMOUNTS'])) {
-                       $path = $folderPath;
-                       if (!$path || !@is_dir($path))  {
-                                       // The closest TEMP-path is found
-                               $path = $this->fileProcessor->findTempFolder().'/';
+               if (!$this->readOnly) {
+                               // Add upload form if allowed
+                       if (!$selectedFolder) {
+                               $fileStorages = $GLOBALS['BE_USER']->getFileStorages();
+                               $fileStorage = reset($fileStorages);
+                               $selectedFolder = $fileStorage->getRootLevelFolder();
                        }
-                       if ($path!='/' && @is_dir($path)) {
-                               $uploadForm=$this->uploadForm($path);
-                               $createFolder=$this->createFolder($path);
+                       if ($selectedFolder) {
+                               $uploadForm = $this->uploadForm($selectedFolder);
+                               $createFolder = $this->createFolder($selectedFolder);
                        } else {
-                               $createFolder='';
-                               $uploadForm='';
-                       }
-                       $content .= $uploadForm;
-                       if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
-                               $content.=$createFolder;
+                               $uploadForm = $createFolder = '';
                        }
-               }
-               return $content;
-       }
-
-       /***************************
-        *
-        * OTHER FUNCTIONS:
-        *
-        ***************************/
-       /**
-        * @param       [type]          $expandFolder: ...
-        * @param       [type]          $plainFlag: ...
-        * @return      [type]          ...
-        */
-       function expandFolder($expandFolder=0,$plainFlag=0,$noThumbs=0) {
-               global $LANG, $BACK_PATH;
-
-               $expandFolder = $expandFolder ? $expandFolder :t3lib_div::_GP('expandFolder');
-               $out='';
-
-               if ($expandFolder && $this->checkFolder($expandFolder)) {
-                       $files = t3lib_div::getFilesInDir($expandFolder,($plainFlag?'jpg,jpeg,gif,png':$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),1,1);       // $extensionList="",$prependPath=0,$order="")
-                       if (is_array($files))   {
-                               $out.=$this->barheader(sprintf($LANG->getLL('images').' (%s):',count($files)));
-
-                               $titleLen = intval($GLOBALS['BE_USER']->uc['titleLen']);
-                               $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
-                               $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
-                               $out.='<span class="nobr">'.$picon.'</span><br />';
-
-                               $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
-                               $imgObj->init();
-                               $imgObj->mayScaleUp=0;
-                               $imgObj->tempPath=PATH_site.$imgObj->tempPath;
-
-                               $lines=array();
-                               foreach ($files as $filepath) {
-                                       $fI=pathinfo($filepath);
-
-                                       $origFile = t3lib_div::rawUrlEncodeFP(substr($filepath,strlen(PATH_site)));
-                                       $iurl = $this->siteURL.$origFile;
-                                       $imgInfo = $imgObj->getImageDimensions($filepath);
-                                               // File icon:
-                                       $icon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
-                                       $pDim = $imgInfo[0].'x'.$imgInfo[1].' '.$LANG->getLL('pixels',1);
-                                       $size=' ('.t3lib_div::formatSize(filesize($filepath)).$LANG->getLL('bytes',1).', '.$pDim.')';
-                                       $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$icon.'','width="18" height="16"').' title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
-                                       $ATag = '<a href="#" onclick="return jumpToUrl(\'?editorNo='.$this->editorNo.'&insertImage='.rawurlencode($filepath).'\');">';
-                                       $ATag_e='</a>';
-                                       if ($plainFlag && (($imgInfo[0] > $this->plainMaxWidth) || ($imgInfo[1] > $this->plainMaxHeight)))      {
-                                               $ATag='';
-                                               $ATag_e='';
-                                               $ATag2='';
-                                               $ATag2_e='';
-                                       } else {
-                                               $ATag2='<a href="#" onClick="launchView(\''.rawurlencode($filepath).'\'); return false;">';
-                                               $ATag2_e='</a>';
-                                       }
-
-                                       $filenameAndIcon=$ATag.$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen)).$ATag_e;
-
-
-                                       $lines[]='<tr class="bgColor4"><td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td><td nowrap="nowrap">'.$pDim.'&nbsp;</td></tr>';
-                                       $lines[]='<tr><td colspan="2">'.($noThumbs ? '' : $ATag2.t3lib_BEfunc::getThumbNail($this->doc->backPath.'thumbs.php',$filepath,'hspace="5" vspace="5" border="1"').$ATag2_e).
-                                               '</td></tr>';
-                                       $lines[]='<tr><td colspan="2"><img src="clear.gif" width="1" height="3"></td></tr>';
-                               }
-                               $out.='<table border="0" cellpadding="0" cellspacing="1">'.implode('',$lines).'</table>';
-                       }
-               }
-               return $out;
-       }
-
-       /**
-        * For RTE: This displays all IMAGES (gif,png,jpg) (from extensionList) from folder. Thumbnails are shown for images.
-        * This listing is of images located in the web-accessible paths ONLY - the listing is for drag-n-drop use in the RTE
-        *
-        * @param       string          The folder path to expand
-        * @param       string          List of fileextensions to show
-        * @return      string          HTML output
-        */
-       function TBE_dragNDrop($expandFolder=0,$extensionList='')       {
-               global $BACK_PATH;
-
-               $expandFolder = $expandFolder ? $expandFolder : t3lib_div::_GP('expandFolder');
-               $out='';
-               if ($expandFolder && $this->checkFolder($expandFolder)) {
-                       if ($this->isWebFolder($expandFolder))  {
-
-                                       // Read files from directory:
-                               $files = t3lib_div::getFilesInDir($expandFolder,$extensionList,1,1);    // $extensionList="",$prependPath=0,$order='')
-                               if (is_array($files))   {
-                                       $out.=$this->barheader(sprintf($GLOBALS['LANG']->getLL('files').' (%s):',count($files)));
-
-                                       $titleLen=intval($GLOBALS['BE_USER']->uc['titleLen']);
-                                       $picon='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/_icon_webfolders.gif','width="18" height="16"').' alt="" />';
-                                       $picon.=htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($expandFolder),$titleLen));
-                                       $out.=$picon.'<br />';
-
-                                               // Init row-array:
-                                       $lines=array();
-
-                                               // Add "drag-n-drop" message:
-                                       $lines[]='
-                                               <tr>
-                                                       <td colspan="2">'.$this->getMsgBox($GLOBALS['LANG']->getLL('findDragDrop')).'</td>
-                                               </tr>';
-
-                                               // Traverse files:
-                                       foreach ($files as $filepath) {
-                                               $fI = pathinfo($filepath);
-
-                                                       // URL of image:
-                                               $iurl = $this->siteURL.t3lib_div::rawurlencodeFP(substr($filepath,strlen(PATH_site)));
-
-                                                       // Show only web-images
-                                               if (t3lib_div::inList('gif,jpeg,jpg,png',strtolower($fI['extension']))) {
-                                                       $imgInfo = @getimagesize($filepath);
-                                                       $pDim = $imgInfo[0].'x'.$imgInfo[1].' pixels';
-
-                                                       $ficon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
-                                                       $size=' ('.t3lib_div::formatSize(filesize($filepath)).'bytes'.($pDim?', '.$pDim:'').')';
-                                                       $icon = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/fileicons/'.$ficon,'width="18" height="16"').' class="absmiddle" title="'.htmlspecialchars($fI['basename'].$size).'" alt="" />';
-                                                       $filenameAndIcon=$icon.htmlspecialchars(t3lib_div::fixed_lgd_cs(basename($filepath),$titleLen));
-
-                                                       if (t3lib_div::_GP('noLimit'))  {
-                                                               $maxW=10000;
-                                                               $maxH=10000;
-                                                       } else {
-                                                               $maxW=380;
-                                                               $maxH=500;
-                                                       }
-                                                       $IW = $imgInfo[0];
-                                                       $IH = $imgInfo[1];
-                                                       if ($IW>$maxW)  {
-                                                               $IH=ceil($IH/$IW*$maxW);
-                                                               $IW=$maxW;
-                                                       }
-                                                       if ($IH>$maxH)  {
-                                                               $IW=ceil($IW/$IH*$maxH);
-                                                               $IH=$maxH;
-                                                       }
-
-                                                               // Make row:
-                                                       $lines[]='
-                                                               <tr class="bgColor4">
-                                                                       <td nowrap="nowrap">'.$filenameAndIcon.'&nbsp;</td>
-                                                                       <td nowrap="nowrap">'.
-                                                                       ($imgInfo[0]!=$IW ? '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('noLimit'=>'1'))).'">'.
-                                                                                                               '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/icon_warning2.gif','width="18" height="16"').' title="'.$GLOBALS['LANG']->getLL('clickToRedrawFullSize',1).'" alt="" />'.
-                                                                                                               '</a>':'').
-                                                                       $pDim.'&nbsp;</td>
-                                                               </tr>';
-                                                               // Remove hardcoded border="1"
-                                                               // Add default class for images
-                                                       $lines[]='
-                                                               <tr>
-                                                                       <td colspan="2"><img src="'.$iurl.'" width="'.$IW.'" height="'.$IH.'" alt=""' . ($this->defaultClass?(' class="'.$this->defaultClass.'"'):''). ' style="cursor:move;" /></td>
-                                                               </tr>';
-                                                       $lines[]='
-                                                               <tr>
-                                                                       <td colspan="2"><img src="clear.gif" width="1" height="3" alt="" /></td>
-                                                               </tr>';
-                                               }
-                                       }
-
-                                               // Finally, wrap all rows in a table tag:
-                                       $out.='
-
-
-                       <!--
-                               File listing / Drag-n-drop
-                       -->
-                                               <table border="0" cellpadding="0" cellspacing="1" id="typo3-dragBox">
-                                                       '.implode('',$lines).'
-                                               </table>';
+                       if ($GLOBALS['BE_USER']->getTSConfigVal('options.uploadFieldsInTopOfEB')) {
+                               $content .= $uploadForm;
+                               if ($GLOBALS['BE_USER']->isAdmin() || $GLOBALS['BE_USER']->getTSConfigVal('options.createFoldersInEB')) {
+                                       $content .= $createFolder;
                                }
-                       } else {
-                                       // Print this warning if the folder is NOT a web folder:
-                               $out.=$this->barheader($GLOBALS['LANG']->getLL('files'));
-                               $out.=$this->getMsgBox($GLOBALS['LANG']->getLL('noWebFolder'),'icon_warning2');
                        }
                }
-               return $out;
+               return $content;
        }
 
        /**
@@ -1117,7 +935,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      void
         */
-        public function initConfiguration() {
+        public function initConfiguration(){
                $this->thisConfig = $this->getRTEConfig();
                $this->buttonConfig = $this->getButtonConfig();
                $this->imgPath = $this->getImgPath();
@@ -1131,7 +949,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      array           RTE configuration array
         */
-       protected function getRTEConfig()       {
+       protected function getRTEConfig() {
                $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
                $RTEsetup = $GLOBALS['BE_USER']->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
                return t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
@@ -1142,7 +960,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      string          path to the image
         */
-       protected function getImgPath() {
+       protected function getImgPath() {
                $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
                return $RTEtsConfigParts[6];
        }
@@ -1152,7 +970,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         *
         * @return      array           the configuration array of the image button
         */
-       protected function getButtonConfig()    {
+       protected function getButtonConfig() {
                return ((is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.'])) ? $this->thisConfig['buttons.']['image.'] : array());
        }
 
@@ -1162,7 +980,7 @@ class tx_rtehtmlarea_select_image extends browse_links {
         * @param       string          $items: initial list of possible items
         * @return      array           the allowed items
         */
-       public function getAllowedItems($items) {
+       public function getAllowedItems($items) {
                $allowedItems = explode(',', $items);
                $clientInfo = t3lib_div::clientInfo();
                if ($clientInfo['BROWSER'] !== 'opera') {
@@ -1249,22 +1067,162 @@ class tx_rtehtmlarea_select_image extends browse_links {
         * @return      string  the text of the message
         */
        public function getHelpMessage($act) {
-               global $LANG;
                switch ($act)   {
                        case 'plain':
-                               return sprintf($LANG->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
+                               return sprintf($GLOBALS['LANG']->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
                                break;
                        case 'magic':
-                               return sprintf($LANG->getLL('magicImage_msg'));
+                               return sprintf($GLOBALS['LANG']->getLL('magicImage_msg'));
                                break;
                        default:
                                return '';
                }
        }
-}
 
+       /**
+        * Render list of files.
+        *
+        * @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
+        */
+       function fileList(array $files, t3lib_file_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 = t3lib_iconWorks::getSpriteIconForFile('folder');
+                               $lines[] = '<tr class="t3-row-header">
+                                       <td colspan="4">' . $folderIcon . htmlspecialchars(t3lib_div::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 t3lib_stdGraphic */
+                       $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
+                       $imgObj->init();
+                       $imgObj->mayScaleUp = 0;
+                       $imgObj->tempPath = PATH_site . $imgObj->tempPath;
+
+                               // Traverse the file list:
+                       /** @var $fileObject t3lib_file_File */
+                       foreach ($files as $fileObject) {
+                               $fileExtension = $fileObject->getExtension();
+                                       // Thumbnail/size generation:
+                               if (t3lib_div::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
+                                       $imageUrl = $fileObject->process(t3lib_file_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 = ' ('.t3lib_div::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
+                               $icon = t3lib_iconWorks::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)) || !t3lib_div::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(t3lib_div::getIndpEnv('REQUEST_URI'));
+                               $ATag2='<a href="'.htmlspecialchars($Ahref).'">';
+                               $ATag2_e='</a>';
+
+                                       // Combine the stuff:
+                               $filenameAndIcon = $ATag_alt . $icon . htmlspecialchars(t3lib_div::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'.t3lib_iconWorks::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' . t3lib_iconWorks::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;
+       }
+}
 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php'])) {
        include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/rtehtmlarea/mod4/class.tx_rtehtmlarea_select_image.php']);
 }
-
 ?>