[TASK] Remove duplicated method in Rtehtmlarea\SelectImage 14/27414/4
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Fri, 7 Feb 2014 14:06:21 +0000 (15:06 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Sat, 8 Feb 2014 18:41:39 +0000 (19:41 +0100)
fileList() of Rtehtmlarea\SelectImage is almost an exact copy
of the parent implementation from ElementBrowser.

The patch removes fileList() from SelectImage and merges changes
to ElementBrowser.

It also fixes some bugs in magic image selector from RTE:
* Missing columns
* Wrong links to info page
* Fix "import selection" option

Resolves: #55765
Releases: 6.2
Change-Id: I78cb23de16b9516f953628aad10cf548f558bfd7
Reviewed-on: https://review.typo3.org/27414
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Marcin Sągol
Tested-by: Marcin Sągol
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/rtehtmlarea/Classes/SelectImage.php

index 399544c..e8acd8f 100644 (file)
@@ -1768,6 +1768,7 @@ class ElementBrowser {
         */
        protected function fileList(array $files, Folder $folder = NULL, $noThumbs = FALSE) {
                $out = '';
         */
        protected function fileList(array $files, Folder $folder = NULL, $noThumbs = FALSE) {
                $out = '';
+
                $lines = array();
                // Create headline (showing number of files):
                $filesCount = count($files);
                $lines = array();
                // Create headline (showing number of files):
                $filesCount = count($files);
@@ -1789,13 +1790,14 @@ class ElementBrowser {
                                        <td colspan="4">No files found.</td>
                                </tr>';
                }
                                        <td colspan="4">No files found.</td>
                                </tr>';
                }
-               // Init graphic object for reading file dimensions:
+               // Init graphic object for reading file and image dimensions:
                /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
                $imgObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
                $imgObj->init();
                $imgObj->mayScaleUp = 0;
                $imgObj->tempPath = PATH_site . $imgObj->tempPath;
                // Traverse the file list:
                /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
                $imgObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
                $imgObj->init();
                $imgObj->mayScaleUp = 0;
                $imgObj->tempPath = PATH_site . $imgObj->tempPath;
                // Traverse the file list:
+               /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
                foreach ($files as $fileObject) {
                        $fileExtension = $fileObject->getExtension();
                        // Thumbnail/size generation:
                foreach ($files as $fileObject) {
                        $fileExtension = $fileObject->getExtension();
                        // Thumbnail/size generation:
@@ -1825,10 +1827,17 @@ class ElementBrowser {
                                'fileExt' => $fileExtension,
                                'fileIcon' => $icon
                        );
                                'fileExt' => $fileExtension,
                                'fileIcon' => $icon
                        );
-                       $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
-                       $ATag_alt = substr($ATag, 0, -4) . ',1);">';
-                       $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
-                       $ATag_e = '</a>';
+                       if ($this->act === 'plain' && ($imgInfo[0] > $this->plainMaxWidth || $imgInfo[1] > $this->plainMaxHeight) || !GeneralUtility::inList('jpg,jpeg,gif,png', $fileExtension)) {
+                               $ATag = '';
+                               $ATag_alt = '';
+                               $ATag_e = '';
+                               $bulkCheckBox = '';
+                       } else {
+                               $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
+                               $ATag_alt = substr($ATag, 0, -4) . ',1);">';
+                               $bulkCheckBox = '<input type="checkbox" class="typo3-bulk-item" name="file_' . $filesIndex . '" value="0" /> ';
+                               $ATag_e = '</a>';
+                       }
                        // Create link to showing details about the file in a window:
                        $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid='
                                . rawurlencode($fileObject->getCombinedIdentifier())
                        // Create link to showing details about the file in a window:
                        $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=_FILE&uid='
                                . rawurlencode($fileObject->getCombinedIdentifier())
@@ -1839,14 +1848,14 @@ class ElementBrowser {
                        $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon
                                . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
                        // Show element:
                        $filenameAndIcon = $bulkCheckBox . $ATag_alt . $icon
                                . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
                        // Show element:
-                       // Image...
                        if ($pDim) {
                        if ($pDim) {
+                               // Image...
                                $lines[] = '
                                        <tr class="file_list_normal">
                                                <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
                                $lines[] = '
                                        <tr class="file_list_normal">
                                                <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                               <td>' . $ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
+                                               <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
                                                        'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
                                                        'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
-                                                       . '" alt="" />' . $ATag_e . '</td>
+                                                       . '" alt="" />' . $ATag_e) . '</td>
                                                <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
                                                        'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
                                                        . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
                                                <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
                                                        'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
                                                        . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
@@ -1861,9 +1870,9 @@ class ElementBrowser {
                                $lines[] = '
                                        <tr class="file_list_normal">
                                                <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
                                $lines[] = '
                                        <tr class="file_list_normal">
                                                <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                               <td>' . $ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
+                                               <td>' . ($ATag . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/plusbullet2.gif',
                                                        'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
                                                        'width="18" height="16"') . ' title="' . $GLOBALS['LANG']->getLL('addToList', TRUE)
-                                                       . '" alt="" />' . $ATag_e . '</td>
+                                                       . '" alt="" />' . $ATag_e) . '</td>
                                                <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
                                                        'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
                                                        . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
                                                <td nowrap="nowrap">' . ($ATag2 . '<img' . IconUtility::skinImg($GLOBALS['BACK_PATH'],
                                                        'gfx/zoom2.gif', 'width="12" height="12"') . ' title="'
                                                        . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> '
index b995dbb..f1a4a5f 100644 (file)
@@ -999,135 +999,4 @@ class SelectImage extends \TYPO3\CMS\Recordlist\Browser\ElementBrowser {
                }
        }
 
                }
        }
 
-       /**
-        * Render list of files.
-        *
-        * @param       array           List of files. See \TYPO3\CMS\Core\Utility\GeneralUtility::getFilesInDir
-        * @param       string          If set a header with a folder icon and folder name are shown
-        * @param       boolean         Whether to show thumbnails or not. If set, no thumbnails are shown.
-        * @return      string          HTML output
-        * @todo Define visibility
-        */
-       public function fileList(array $files, \TYPO3\CMS\Core\Resource\Folder $folder = NULL, $noThumbs = 0) {
-               $out = '';
-               // Listing the files:
-               if (is_array($files)) {
-                       $lines = array();
-                       // Create headline (showing number of files):
-                       $filesCount = count($files);
-                       $out .= $this->barheader(sprintf($GLOBALS['LANG']->getLL('files') . ' (%s):', $filesCount));
-                       $out .= '<div id="filelist">';
-                       $out .= $this->getBulkSelector($filesCount);
-                       $titleLen = (int)$GLOBALS['BE_USER']->uc['titleLen'];
-                       // Create the header of current folder:
-                       if ($folder) {
-                               $folderIcon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile('folder');
-                               $lines[] = '<tr class="t3-row-header">
-                                       <td colspan="4">' . $folderIcon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($folder->getIdentifier(), $titleLen)) . '</td>
-                               </tr>';
-                       }
-                       if ($filesCount == 0) {
-                               $lines[] = '
-                                       <tr class="file_list_normal">
-                                               <td colspan="4">No files found.</td>
-                                       </tr>';
-                       }
-                       // Init graphic object for reading file and image dimensions:
-                       /** @var $imgObj \TYPO3\CMS\Core\Imaging\GraphicalFunctions */
-                       $imgObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Imaging\\GraphicalFunctions');
-                       $imgObj->init();
-                       $imgObj->mayScaleUp = 0;
-                       $imgObj->tempPath = PATH_site . $imgObj->tempPath;
-                       // Traverse the file list:
-                       /** @var $fileObject \TYPO3\CMS\Core\Resource\File */
-                       foreach ($files as $fileObject) {
-                               $fileExtension = $fileObject->getExtension();
-                               // Thumbnail/size generation:
-                               if (GeneralUtility::inList(strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']), strtolower($fileExtension)) && !$noThumbs) {
-                                       $imageUrl = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array('width' => 64, 'height' => 64))->getPublicUrl(TRUE);
-                                       $imgInfo = $imgObj->getImageDimensions($fileObject->getForLocalProcessing(FALSE));
-                                       $pDim = $imgInfo[0] . 'x' . $imgInfo[1] . ' pixels';
-                                       $clickIcon = '<img src="' . $imageUrl . '" hspace="5" vspace="5" border="1"';
-                               } else {
-                                       $clickIcon = '';
-                                       $pDim = '';
-                               }
-                               // Create file icon:
-                               $size = ' (' . GeneralUtility::formatSize($fileObject->getSize()) . 'bytes' . ($pDim ? ', ' . $pDim : '') . ')';
-                               $icon = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($fileExtension, array('title' => $fileObject->getName() . $size));
-                               // Create links for adding the file:
-                               $filesIndex = count($this->elements);
-                               $this->elements['file_' . $filesIndex] = array(
-                                       'type' => 'file',
-                                       'table' => 'sys_file',
-                                       'uid' => $fileObject->getUid(),
-                                       'fileName' => $fileObject->getName(),
-                                       'filePath' => $fileObject->getUid(),
-                                       'fileExt' => $fileExtension,
-                                       'fileIcon' => $icon
-                               );
-                               $element = $this->elements['file_' . $filesIndex];
-                               if ($this->act === 'plain' && ($imgInfo[0] > $this->plainMaxWidth || $imgInfo[1] > $this->plainMaxHeight) || !GeneralUtility::inList('jpg,jpeg,gif,png', $fileExtension)) {
-                                       $ATag = '';
-                                       $ATag_alt = '';
-                                       $ATag_e = '';
-                               } else {
-                                       $this->elements['file_' . $filesIndex] = array(
-                                               'type' => 'file',
-                                               'table' => 'sys_file',
-                                               'uid' => $fileObject->getUid(),
-                                               'fileName' => $fileObject->getName(),
-                                               'filePath' => $fileObject->getUid(),
-                                               'fileExt' => $fileExtension,
-                                               'fileIcon' => $icon
-                                       );
-                                       $ATag = '<a href="#" onclick="return BrowseLinks.File.insertElement(\'file_' . $filesIndex . '\');">';
-                                       $ATag_alt = substr($ATag, 0, -4) . ',1);">';
-                                       $ATag_e = '</a>';
-                               }
-                               // Create link to showing details about the file in a window:
-                               $Ahref = $GLOBALS['BACK_PATH'] . 'show_item.php?type=file&table=' . rawurlencode($fileObject->getCombinedIdentifier()) . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
-                               $ATag2 = '<a href="' . htmlspecialchars($Ahref) . '">';
-                               $ATag2_e = '</a>';
-                               // Combine the stuff:
-                               $filenameAndIcon = $ATag_alt . $icon . htmlspecialchars(GeneralUtility::fixed_lgd_cs($fileObject->getName(), $titleLen)) . $ATag_e;
-                               // Show element:
-                               if ($pDim) {
-                                       // Image...
-                                       $lines[] = '
-                                               <tr class="file_list_normal">
-                                                       <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                                       <td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', TRUE) . $ATag2_e) . '</td>
-                                                       <td nowrap="nowrap">&nbsp;' . $pDim . '</td>
-                                               </tr>';
-                                       $lines[] = '
-                                               <tr>
-                                                       <td class="filelistThumbnail" colspan="4">' . $ATag_alt . $clickIcon . $ATag_e . '</td>
-                                               </tr>';
-                               } else {
-                                       $lines[] = '
-                                               <tr class="file_list_normal">
-                                                       <td nowrap="nowrap">' . $filenameAndIcon . '&nbsp;</td>
-                                                       <td nowrap="nowrap">' . ($ATag2 . '<img' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($GLOBALS['BACK_PATH'], 'gfx/zoom2.gif', 'width="12" height="12"') . ' title="' . $GLOBALS['LANG']->getLL('info', TRUE) . '" alt="" /> ' . $GLOBALS['LANG']->getLL('info', TRUE) . $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;
-       }
-
 }
 }