[TASK] file_list: use t3-table & semantic HTML in localization
[Packages/TYPO3.CMS.git] / typo3 / sysext / filelist / Classes / FileList.php
index 47285f3..2a4a937 100644 (file)
@@ -266,7 +266,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
        public function linkClipboardHeaderIcon($string, $table, $cmd, $warning = '') {
                $onClickEvent = 'document.dblistForm.cmd.value=\'' . $cmd . '\';document.dblistForm.submit();';
                if ($warning) {
-                       $onClickEvent = 'if (confirm(' . $GLOBALS['LANG']->JScharCode($warning) . ')){' . $onClickEvent . '}';
+                       $onClickEvent = 'if (confirm(' . GeneralUtility::quoteJSvalue($warning) . ')){' . $onClickEvent . '}';
                }
                return '<a href="#" onclick="' . htmlspecialchars($onClickEvent) . 'return false;">' . $string . '</a>';
        }
@@ -319,7 +319,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                        $filesToSort[$sortingKey . $i] = $fileObject;
                                }
                                uksort($filesToSort, 'strnatcasecmp');
-                               if (intval($this->sortRev) === 1) {
+                               if ((int)$this->sortRev === 1) {
                                        $filesToSort = array_reverse($filesToSort);
                                }
                                $files = $filesToSort;
@@ -346,12 +346,6 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
 
                        // Directories are added
                        $iOut = $this->formatDirList($folderObjects);
-                       if ($iOut) {
-                               // Half line is drawn
-                               $theData = array(
-                                       $titleCol => ''
-                               );
-                       }
                        // Files are added
                        $iOut .= $this->formatFileList($files, $titleCol);
                        // Header line is drawn
@@ -378,19 +372,18 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                }
                        }
 
-                       if (!empty($iOut)) {
-                               $out .= '<thead>' . $this->addelement(1, '&nbsp;', $theData, ' class="t3-row-header"', '') . '</thead>';
-                               $out .= '<tbody>' . $iOut . '</tbody>';
-                               // half line is drawn
-                               // finish
-                               $out = '
+                       $out .= '<thead>' . $this->addelement(1, '&nbsp;', $theData) . '</thead>';
+                       $out .= '<tbody>' . $iOut . '</tbody>';
+                       // half line is drawn
+                       // finish
+                       $out = '
                <!--
                        File list table:
                -->
-                       <table cellpadding="0" cellspacing="0" id="typo3-filelist">
+                       <table class="t3-table" id="typo3-filelist">
                                ' . $out . '
                        </table>';
-                       }
+
                } else {
                        /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
                        $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('storageNotBrowsableMessage'), $GLOBALS['LANG']->getLL('storageNotBrowsableTitle'), \TYPO3\CMS\Core\Messaging\FlashMessage::INFO);
@@ -522,7 +515,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                }
                                        }
                                }
-                               $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
+                               $out .= $this->addelement(1, $theIcon, $theData);
                        }
                        $this->eCounter++;
                        $this->dirCounter = $this->eCounter;
@@ -612,7 +605,15 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
        public function formatFileList(array $files) {
                $out = '';
                // first two keys are "0" (default) and "-1" (multiple), after that comes the "other languages"
-               $systemLanguages = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
+               $allSystemLanguages = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Configuration\\TranslationConfigurationProvider')->getSystemLanguages();
+               $systemLanguages = array_filter($allSystemLanguages, function($languageRecord) {
+                       if ($languageRecord['uid'] === -1 || $languageRecord['uid'] === 0 || !$GLOBALS['BE_USER']->checkLanguageAccess($languageRecord['uid'])) {
+                               return FALSE;
+                       } else {
+                               return TRUE;
+                       }
+               });
+
                foreach ($files as $fileObject) {
                        list($flag, $code) = $this->fwd_rwd_nav();
                        $out .= $code;
@@ -649,7 +650,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                                $temp .= $this->makeEdit($fileObject);
                                                        }
                                                        $temp .= $this->makeClip($fileObject);
-                                                       if (count($systemLanguages) > 2) {
+                                                       if (!empty($systemLanguages)) {
                                                                $temp .= '<a class="filelist-translationToggler" data-fileid="' . $fileObject->getUid() . '">' .
                                                                        IconUtility::getSpriteIcon('mimetypes-x-content-page-language-overlay') . '</a>';
                                                        }
@@ -669,9 +670,46 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                                $processedFile = $fileObject->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
                                                                if ($processedFile) {
                                                                        $thumbUrl = $processedFile->getPublicUrl(TRUE);
-                                                                       $theData[$field] .= '<br /><img src="' . $thumbUrl . '" hspace="2" title="' . htmlspecialchars($fileName) . '" alt="" />';
+                                                                       $theData[$field] .= '<br /><img src="' . $thumbUrl . '" title="' . htmlspecialchars($fileName) . '" alt="" />';
                                                                }
                                                        }
+
+                                                       if (!empty($systemLanguages)) {
+                                                               $metaDataRecord = $fileObject->_getMetaData();
+                                                               $translations = $this->getTranslationsForMetaData($metaDataRecord);
+                                                               $languageCode = '';
+
+                                                               foreach ($systemLanguages as $language) {
+                                                                       $languageId = $language['uid'];
+                                                                       $flagIcon = $language['flagIcon'];
+
+                                                                       if (array_key_exists($languageId, $translations)) {
+                                                                               $flagButtonIcon = IconUtility::getSpriteIcon(
+                                                                                       'actions-document-open',
+                                                                                       array('title' => $fileName),
+                                                                                       array($flagIcon . '-overlay' => array()));
+                                                                               $data = array(
+                                                                                       'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
+                                                                               );
+                                                                               $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
+                                                                               $languageCode .= sprintf('<a href="#" onclick="%s">%s</a>', htmlspecialchars($editOnClick), $flagButtonIcon);
+
+                                                                       } else {
+                                                                               $href = $GLOBALS['SOBE']->doc->issueCommand(
+                                                                                       '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
+                                                                                       $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
+                                                                                       '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility::getUrlToken('editRecord')
+                                                                               );
+                                                                               $flagButtonIcon = IconUtility::getSpriteIcon($flagIcon);
+                                                                               $languageCode .= sprintf('<a href="%s">%s</a> ', htmlspecialchars($href), $flagButtonIcon);
+                                                                       }
+                                                               }
+
+                                                               // Hide flag button bar when not translated yet
+                                                               $theData[$field] .= '<div class="localisationData" data-fileid="' . $fileObject->getUid() . '"' .
+                                                                               (empty($translations) ? ' style="display: none;"' : '') . '>' . $languageCode . '</div>';
+                                                       }
+
                                                        break;
                                                default:
                                                        $theData[$field] = '';
@@ -680,43 +718,8 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                                                        }
                                        }
                                }
-                               $out .= $this->addelement(1, $theIcon, $theData, ' class="file_list_normal"');
-
-                               $metaDataRecord = $fileObject->_getMetaData();
-                               $translations = $this->getTranslationsForMetaData($metaDataRecord);
-                               if (count($systemLanguages) > 2) {
-                                       $code = IconUtility::getSpriteIcon('empty-empty');
-                                       foreach ($systemLanguages as $language) {
-                                               $languageId = $language['uid'];
-                                               if ($languageId == -1 || $languageId == 0) {
-                                                       continue;
-                                               }
-                                               $flagIcon = $language['flagIcon'];
-                                               if (array_key_exists($languageId, $translations)) {
-
-                                                       $theIcon = IconUtility::getSpriteIcon(
-                                                               'actions-document-open',
-                                                               array('title' => $fileName),
-                                                               array($flagIcon . '-overlay' => array()));
-                                                       $data = array(
-                                                               'sys_file_metadata' => array($translations[$languageId]['uid'] => 'edit')
-                                                       );
-                                                       $editOnClick = BackendUtility::editOnClick(GeneralUtility::implodeArrayForUrl('edit', $data), $GLOBALS['BACK_PATH'], $this->listUrl());
-                                                       $code .= sprintf('<a href="#" onclick="%s">%s</a>', htmlspecialchars($editOnClick), $theIcon);
-
-                                               } else {
-                                                       $href = $GLOBALS['SOBE']->doc->issueCommand(
-                                                               '&cmd[sys_file_metadata][' . $metaDataRecord['uid'] . '][localize]=' . $languageId,
-                                                               $this->backPath . 'alt_doc.php?justLocalized=' . rawurlencode(('sys_file_metadata:' . $metaDataRecord['uid'] . ':' . $languageId)) .
-                                                               '&returnUrl=' . rawurlencode($this->listURL()) . BackendUtility::getUrlToken('editRecord')
-                                                       );
-                                                       $theIcon = IconUtility::getSpriteIcon($flagIcon);
-
-                                                       $code .= sprintf('<a href="%s">%s</a>', htmlspecialchars($href), $theIcon);
-                                               }
-                                       }
-                                       $out .= '<tr class="file_list_normal localisationData" data-fileid="' . $fileObject->getUid() . '"><td></td><td colspan="' . count($this->fieldArray) . '">' . $code . '</td></tr>';
-                               }
+                               $out .= $this->addelement(1, $theIcon, $theData);
+
                        }
                        $this->eCounter++;
                }
@@ -730,7 +733,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
         * @return array keys are the sys_language uids, values are the $rows
         */
        protected function getTranslationsForMetaData($metaDataRecord) {
-               $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . intval($metaDataRecord['uid']) .
+               $where = $GLOBALS['TCA']['sys_file_metadata']['ctrl']['transOrigPointerField'] . '=' . (int)$metaDataRecord['uid'] .
                        ' AND ' . $GLOBALS['TCA']['sys_file_metadata']['ctrl']['languageField'] . '>0';
                $translationRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_file_metadata', $where);
                $translations = array();
@@ -869,7 +872,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                        }
 
                        if ($GLOBALS['BE_USER']->jsConfirmation(4)) {
-                               $confirmationCheck = 'confirm(' . $GLOBALS['LANG']->JScharCode(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), basename($identifier)) . $referenceCountText) . ')';
+                               $confirmationCheck = 'confirm(' . GeneralUtility::quoteJSvalue(sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:mess.delete'), basename($identifier)) . $referenceCountText) . ')';
                        } else {
                                $confirmationCheck = '1 == 1';
                        }
@@ -915,7 +918,7 @@ class FileList extends \TYPO3\CMS\Backend\RecordList\AbstractRecordList {
                }
                // Look up the file in the sys_refindex.
                // Exclude sys_file_metadata records as these are no use references
-               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=\'sys_file\' AND ref_uid = ' . (integer)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"');
+               $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=\'sys_file\' AND ref_uid = ' . (int)$fileOrFolderObject->getUid() . ' AND deleted=0 AND tablename != "sys_file_metadata"');
                return $this->generateReferenceToolTip($rows, '\'_FILE\', ' . GeneralUtility::quoteJSvalue($fileOrFolderObject->getCombinedIdentifier()));
        }