@@ -201,7 +201,7 @@ |
||
| 201 | 201 | /** |
| 202 | 202 | * Returns whether the current mode is Frontend |
| 203 | 203 | * |
| 204 | - * @return string |
|
| 204 | + * @return boolean |
|
| 205 | 205 | */ |
| 206 | 206 | protected function isFrontendMode() |
| 207 | 207 | { |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | 'number_of_references' => $totalNumberOfReferences |
| 40 | 40 | ); |
| 41 | 41 | |
| 42 | - $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = ' . $fileIdentifier, $values); |
|
| 42 | + $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = '.$fileIdentifier, $values); |
|
| 43 | 43 | $counter++; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | if ($processedFile->exists()) { |
| 75 | 75 | $processedFile->delete(true); |
| 76 | 76 | } |
| 77 | - $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'uid=' . (int)$processedFile->getUid()); |
|
| 77 | + $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'uid='.(int)$processedFile->getUid()); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
| 128 | 128 | 'DISTINCT pid', |
| 129 | 129 | 'sys_file_reference', |
| 130 | - 'deleted = 0 AND pid > 0 AND uid_local = ' . $file->getUid() |
|
| 130 | + 'deleted = 0 AND pid > 0 AND uid_local = '.$file->getUid() |
|
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | // Compute result |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
| 154 | 154 | 'ref_table = "sys_file"', |
| 155 | 155 | 'tablename = "tt_content"', |
| 156 | - 'ref_uid = ' . $file->getUid(), |
|
| 156 | + 'ref_uid = '.$file->getUid(), |
|
| 157 | 157 | ); |
| 158 | 158 | |
| 159 | 159 | $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
@@ -18,215 +18,215 @@ |
||
| 18 | 18 | class CacheService |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Traverse all files and initialize cache values. |
|
| 23 | - * |
|
| 24 | - * @return int |
|
| 25 | - */ |
|
| 26 | - public function warmUp() |
|
| 27 | - { |
|
| 28 | - |
|
| 29 | - $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', 'storage > 0'); |
|
| 30 | - $resource = $this->getDatabaseConnection()->sql_query($query); |
|
| 31 | - |
|
| 32 | - $counter = 0; |
|
| 33 | - while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
| 34 | - |
|
| 35 | - $fileIdentifier = $row['uid']; |
|
| 36 | - $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
| 37 | - |
|
| 38 | - $values = array( |
|
| 39 | - 'number_of_references' => $totalNumberOfReferences |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = ' . $fileIdentifier, $values); |
|
| 43 | - $counter++; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - return $counter; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Clear all possible cache related to a file. |
|
| 51 | - * This method is useful when replacing a file for instance. |
|
| 52 | - * |
|
| 53 | - * @param File $file |
|
| 54 | - * @return void |
|
| 55 | - */ |
|
| 56 | - public function clearCache(File $file) |
|
| 57 | - { |
|
| 58 | - |
|
| 59 | - $this->clearCachePages($file); |
|
| 60 | - $this->flushProcessedFiles($file); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Remove all processed files that belong to the given File object. |
|
| 65 | - * |
|
| 66 | - * @param File $file |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - protected function flushProcessedFiles(File $file) |
|
| 70 | - { |
|
| 71 | - |
|
| 72 | - /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
| 73 | - foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
| 74 | - if ($processedFile->exists()) { |
|
| 75 | - $processedFile->delete(true); |
|
| 76 | - } |
|
| 77 | - $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'uid=' . (int)$processedFile->getUid()); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Return a processed file repository |
|
| 83 | - * |
|
| 84 | - * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
| 85 | - */ |
|
| 86 | - protected function getProcessedFileRepository() |
|
| 87 | - { |
|
| 88 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Returns the file references. |
|
| 93 | - * |
|
| 94 | - * @param File $file |
|
| 95 | - * @return void |
|
| 96 | - */ |
|
| 97 | - protected function clearCachePages($file) |
|
| 98 | - { |
|
| 99 | - |
|
| 100 | - /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 101 | - $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
| 102 | - $tce->start([], []); |
|
| 103 | - |
|
| 104 | - #$pages = array_merge( |
|
| 105 | - # $this->findPagesWithFileReferences($file), |
|
| 106 | - # $this->findPagesWithSoftReferences($file) |
|
| 107 | - #); |
|
| 108 | - |
|
| 109 | - // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
| 110 | - // It is adviced to use "registerPageCacheClearing" but how? |
|
| 111 | - #foreach (array_unique($pages) as $page) { |
|
| 112 | - # $tce->clear_cache('pages', $page); |
|
| 113 | - #} |
|
| 114 | - $tce->clear_cacheCmd('pages'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Find all pages which contains file references to the given $file. |
|
| 119 | - * |
|
| 120 | - * @param File $file |
|
| 121 | - * @return array |
|
| 122 | - */ |
|
| 123 | - protected function findPagesWithFileReferences($file) |
|
| 124 | - { |
|
| 125 | - |
|
| 126 | - // Get the file references of the file |
|
| 127 | - $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 128 | - 'DISTINCT pid', |
|
| 129 | - 'sys_file_reference', |
|
| 130 | - 'deleted = 0 AND pid > 0 AND uid_local = ' . $file->getUid() |
|
| 131 | - ); |
|
| 132 | - |
|
| 133 | - // Compute result |
|
| 134 | - $pages = []; |
|
| 135 | - while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 136 | - $pages[] = $affectedPage['pid']; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $pages; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Find all pages which have soft references to the given $file. |
|
| 144 | - * |
|
| 145 | - * @param File $file |
|
| 146 | - * @return array |
|
| 147 | - */ |
|
| 148 | - protected function findPagesWithSoftReferences(File $file) |
|
| 149 | - { |
|
| 150 | - |
|
| 151 | - $subClauseParts = array( |
|
| 152 | - 'deleted = 0', |
|
| 153 | - '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 154 | - 'ref_table = "sys_file"', |
|
| 155 | - 'tablename = "tt_content"', |
|
| 156 | - 'ref_uid = ' . $file->getUid(), |
|
| 157 | - ); |
|
| 158 | - |
|
| 159 | - $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 160 | - 'DISTINCT pid', |
|
| 161 | - 'tt_content', |
|
| 162 | - sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 163 | - implode(' AND ', $subClauseParts), |
|
| 164 | - $this->getWhereClauseForEnabledFields('tt_content') |
|
| 165 | - ) |
|
| 166 | - ); |
|
| 167 | - |
|
| 168 | - // Compute result |
|
| 169 | - $pages = []; |
|
| 170 | - while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 171 | - $pages[] = $affectedPage['pid']; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return $pages; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 179 | - * |
|
| 180 | - * @param string $tableName |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - protected function getWhereClauseForEnabledFields($tableName) |
|
| 184 | - { |
|
| 185 | - if ($this->isFrontendMode()) { |
|
| 186 | - // frontend context |
|
| 187 | - $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 188 | - } else { |
|
| 189 | - // backend context |
|
| 190 | - $whereClause = BackendUtility::deleteClause($tableName); |
|
| 191 | - } |
|
| 192 | - return $whereClause; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Returns whether the current mode is Frontend |
|
| 197 | - * |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - protected function isFrontendMode() |
|
| 201 | - { |
|
| 202 | - return TYPO3_MODE == 'FE'; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * Returns an instance of the page repository. |
|
| 207 | - * |
|
| 208 | - * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 209 | - */ |
|
| 210 | - protected function getPageRepository() |
|
| 211 | - { |
|
| 212 | - return $GLOBALS['TSFE']->sys_page; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Returns a pointer to the database. |
|
| 217 | - * |
|
| 218 | - * @return \Fab\Vidi\Database\DatabaseConnection |
|
| 219 | - */ |
|
| 220 | - protected function getDatabaseConnection() |
|
| 221 | - { |
|
| 222 | - return $GLOBALS['TYPO3_DB']; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 227 | - */ |
|
| 228 | - protected function getFileReferenceService() |
|
| 229 | - { |
|
| 230 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 231 | - } |
|
| 21 | + /** |
|
| 22 | + * Traverse all files and initialize cache values. |
|
| 23 | + * |
|
| 24 | + * @return int |
|
| 25 | + */ |
|
| 26 | + public function warmUp() |
|
| 27 | + { |
|
| 28 | + |
|
| 29 | + $query = $this->getDatabaseConnection()->SELECTquery('*', 'sys_file', 'storage > 0'); |
|
| 30 | + $resource = $this->getDatabaseConnection()->sql_query($query); |
|
| 31 | + |
|
| 32 | + $counter = 0; |
|
| 33 | + while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($resource)) { |
|
| 34 | + |
|
| 35 | + $fileIdentifier = $row['uid']; |
|
| 36 | + $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
| 37 | + |
|
| 38 | + $values = array( |
|
| 39 | + 'number_of_references' => $totalNumberOfReferences |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + $this->getDatabaseConnection()->exec_UPDATEquery('sys_file', 'uid = ' . $fileIdentifier, $values); |
|
| 43 | + $counter++; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + return $counter; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Clear all possible cache related to a file. |
|
| 51 | + * This method is useful when replacing a file for instance. |
|
| 52 | + * |
|
| 53 | + * @param File $file |
|
| 54 | + * @return void |
|
| 55 | + */ |
|
| 56 | + public function clearCache(File $file) |
|
| 57 | + { |
|
| 58 | + |
|
| 59 | + $this->clearCachePages($file); |
|
| 60 | + $this->flushProcessedFiles($file); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Remove all processed files that belong to the given File object. |
|
| 65 | + * |
|
| 66 | + * @param File $file |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + protected function flushProcessedFiles(File $file) |
|
| 70 | + { |
|
| 71 | + |
|
| 72 | + /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
| 73 | + foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
| 74 | + if ($processedFile->exists()) { |
|
| 75 | + $processedFile->delete(true); |
|
| 76 | + } |
|
| 77 | + $this->getDatabaseConnection()->exec_DELETEquery('sys_file_processedfile', 'uid=' . (int)$processedFile->getUid()); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Return a processed file repository |
|
| 83 | + * |
|
| 84 | + * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
| 85 | + */ |
|
| 86 | + protected function getProcessedFileRepository() |
|
| 87 | + { |
|
| 88 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Returns the file references. |
|
| 93 | + * |
|
| 94 | + * @param File $file |
|
| 95 | + * @return void |
|
| 96 | + */ |
|
| 97 | + protected function clearCachePages($file) |
|
| 98 | + { |
|
| 99 | + |
|
| 100 | + /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 101 | + $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
| 102 | + $tce->start([], []); |
|
| 103 | + |
|
| 104 | + #$pages = array_merge( |
|
| 105 | + # $this->findPagesWithFileReferences($file), |
|
| 106 | + # $this->findPagesWithSoftReferences($file) |
|
| 107 | + #); |
|
| 108 | + |
|
| 109 | + // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
| 110 | + // It is adviced to use "registerPageCacheClearing" but how? |
|
| 111 | + #foreach (array_unique($pages) as $page) { |
|
| 112 | + # $tce->clear_cache('pages', $page); |
|
| 113 | + #} |
|
| 114 | + $tce->clear_cacheCmd('pages'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Find all pages which contains file references to the given $file. |
|
| 119 | + * |
|
| 120 | + * @param File $file |
|
| 121 | + * @return array |
|
| 122 | + */ |
|
| 123 | + protected function findPagesWithFileReferences($file) |
|
| 124 | + { |
|
| 125 | + |
|
| 126 | + // Get the file references of the file |
|
| 127 | + $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 128 | + 'DISTINCT pid', |
|
| 129 | + 'sys_file_reference', |
|
| 130 | + 'deleted = 0 AND pid > 0 AND uid_local = ' . $file->getUid() |
|
| 131 | + ); |
|
| 132 | + |
|
| 133 | + // Compute result |
|
| 134 | + $pages = []; |
|
| 135 | + while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 136 | + $pages[] = $affectedPage['pid']; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $pages; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Find all pages which have soft references to the given $file. |
|
| 144 | + * |
|
| 145 | + * @param File $file |
|
| 146 | + * @return array |
|
| 147 | + */ |
|
| 148 | + protected function findPagesWithSoftReferences(File $file) |
|
| 149 | + { |
|
| 150 | + |
|
| 151 | + $subClauseParts = array( |
|
| 152 | + 'deleted = 0', |
|
| 153 | + '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 154 | + 'ref_table = "sys_file"', |
|
| 155 | + 'tablename = "tt_content"', |
|
| 156 | + 'ref_uid = ' . $file->getUid(), |
|
| 157 | + ); |
|
| 158 | + |
|
| 159 | + $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 160 | + 'DISTINCT pid', |
|
| 161 | + 'tt_content', |
|
| 162 | + sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 163 | + implode(' AND ', $subClauseParts), |
|
| 164 | + $this->getWhereClauseForEnabledFields('tt_content') |
|
| 165 | + ) |
|
| 166 | + ); |
|
| 167 | + |
|
| 168 | + // Compute result |
|
| 169 | + $pages = []; |
|
| 170 | + while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 171 | + $pages[] = $affectedPage['pid']; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return $pages; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 179 | + * |
|
| 180 | + * @param string $tableName |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + protected function getWhereClauseForEnabledFields($tableName) |
|
| 184 | + { |
|
| 185 | + if ($this->isFrontendMode()) { |
|
| 186 | + // frontend context |
|
| 187 | + $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 188 | + } else { |
|
| 189 | + // backend context |
|
| 190 | + $whereClause = BackendUtility::deleteClause($tableName); |
|
| 191 | + } |
|
| 192 | + return $whereClause; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Returns whether the current mode is Frontend |
|
| 197 | + * |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + protected function isFrontendMode() |
|
| 201 | + { |
|
| 202 | + return TYPO3_MODE == 'FE'; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * Returns an instance of the page repository. |
|
| 207 | + * |
|
| 208 | + * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 209 | + */ |
|
| 210 | + protected function getPageRepository() |
|
| 211 | + { |
|
| 212 | + return $GLOBALS['TSFE']->sys_page; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Returns a pointer to the database. |
|
| 217 | + * |
|
| 218 | + * @return \Fab\Vidi\Database\DatabaseConnection |
|
| 219 | + */ |
|
| 220 | + protected function getDatabaseConnection() |
|
| 221 | + { |
|
| 222 | + return $GLOBALS['TYPO3_DB']; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 227 | + */ |
|
| 228 | + protected function getFileReferenceService() |
|
| 229 | + { |
|
| 230 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -268,7 +268,7 @@ |
||
| 268 | 268 | * Remove accent from a string |
| 269 | 269 | * |
| 270 | 270 | * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297 |
| 271 | - * @param $string |
|
| 271 | + * @param string $string |
|
| 272 | 272 | * @return string |
| 273 | 273 | */ |
| 274 | 274 | protected function unAccent($string) |
@@ -128,8 +128,8 @@ discard block |
||
| 128 | 128 | $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); |
| 129 | 129 | |
| 130 | 130 | if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { |
| 131 | - $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; |
|
| 132 | - $this->throwException('increase post_max_size and upload_max_filesize to ' . $size); |
|
| 131 | + $size = max(1, $this->sizeLimit / 1024 / 1024).'M'; |
|
| 132 | + $this->throwException('increase post_max_size and upload_max_filesize to '.$size); |
|
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $isAllowed = $this->checkFileExtensionPermission($fileName); |
| 198 | 198 | if (!$isAllowed) { |
| 199 | 199 | $these = PermissionUtility::getInstance()->getAllowedExtensionList(); |
| 200 | - $this->throwException('File has an invalid extension, it should be one of ' . $these . '.'); |
|
| 200 | + $this->throwException('File has an invalid extension, it should be one of '.$these.'.'); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function sanitizeFileName($fileName, $slug = '-', $extra = null) |
| 257 | 257 | { |
| 258 | - return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 258 | + return trim(preg_replace('~[^0-9a-z_'.preg_quote($extra, '~').']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | protected function initializeUploadFolder() |
| 295 | 295 | { |
| 296 | - $this->uploadFolder = PATH_site . self::UPLOAD_FOLDER; |
|
| 296 | + $this->uploadFolder = PATH_site.self::UPLOAD_FOLDER; |
|
| 297 | 297 | |
| 298 | 298 | // Initialize the upload folder for file transfer and create it if not yet existing |
| 299 | 299 | if (!file_exists($this->uploadFolder)) { |
@@ -20,362 +20,362 @@ |
||
| 20 | 20 | class UploadManager |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - const UPLOAD_FOLDER = 'typo3temp/pics'; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var int|null|string |
|
| 27 | - */ |
|
| 28 | - protected $sizeLimit; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - protected $uploadFolder; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var FormUtility |
|
| 37 | - */ |
|
| 38 | - protected $formUtility; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var \TYPO3\CMS\Core\Resource\ResourceStorage |
|
| 42 | - */ |
|
| 43 | - protected $storage; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Name of the file input in the DOM. |
|
| 47 | - * |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 50 | - protected $inputName = 'qqfile'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
| 54 | - * @return UploadManager |
|
| 55 | - */ |
|
| 56 | - function __construct($storage = null) |
|
| 57 | - { |
|
| 58 | - |
|
| 59 | - $this->initializeUploadFolder(); |
|
| 60 | - |
|
| 61 | - // max file size in bytes |
|
| 62 | - $this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024; |
|
| 63 | - $this->checkServerSettings(); |
|
| 64 | - |
|
| 65 | - $this->formUtility = FormUtility::getInstance(); |
|
| 66 | - $this->storage = $storage; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Handle the uploaded file. |
|
| 71 | - * |
|
| 72 | - * @return UploadedFileInterface |
|
| 73 | - */ |
|
| 74 | - public function handleUpload() |
|
| 75 | - { |
|
| 76 | - |
|
| 77 | - /** @var $uploadedFile UploadedFileInterface */ |
|
| 78 | - $uploadedFile = false; |
|
| 79 | - if ($this->formUtility->isMultiparted()) { |
|
| 80 | - |
|
| 81 | - // Default case |
|
| 82 | - $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\MultipartedFile::class); |
|
| 83 | - } elseif ($this->formUtility->isOctetStreamed()) { |
|
| 84 | - |
|
| 85 | - // Fine Upload plugin would use it if forceEncoded = false and paramsInBody = false |
|
| 86 | - $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\StreamedFile::class); |
|
| 87 | - } elseif ($this->formUtility->isUrlEncoded()) { |
|
| 88 | - |
|
| 89 | - // Used for image resizing in BE |
|
| 90 | - $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\Base64File::class); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if (!$uploadedFile) { |
|
| 94 | - $this->throwException('Could not instantiate an upload object... No file was uploaded?'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $fileName = $this->getFileName($uploadedFile); |
|
| 98 | - |
|
| 99 | - $this->checkFileSize($uploadedFile->getSize()); |
|
| 100 | - $this->checkFileAllowed($fileName); |
|
| 101 | - |
|
| 102 | - $saved = $uploadedFile->setInputName($this->inputName) |
|
| 103 | - ->setUploadFolder($this->uploadFolder) |
|
| 104 | - ->setName($fileName) |
|
| 105 | - ->save(); |
|
| 106 | - |
|
| 107 | - if (!$saved) { |
|
| 108 | - $this->throwException('Could not save uploaded file. The upload was cancelled, or server error encountered'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Optimize file if the uploaded file is an image. |
|
| 112 | - if ($uploadedFile->getType() == \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE) { |
|
| 113 | - $uploadedFile = ImageOptimizer::getInstance($this->storage)->optimize($uploadedFile); |
|
| 114 | - } |
|
| 115 | - return $uploadedFile; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Internal function that checks if server's may sizes match the |
|
| 120 | - * object's maximum size for uploads. |
|
| 121 | - * |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - protected function checkServerSettings() |
|
| 125 | - { |
|
| 126 | - $postSize = $this->toBytes(ini_get('post_max_size')); |
|
| 127 | - |
|
| 128 | - $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); |
|
| 129 | - |
|
| 130 | - if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { |
|
| 131 | - $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; |
|
| 132 | - $this->throwException('increase post_max_size and upload_max_filesize to ' . $size); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Convert a given size with units to bytes. |
|
| 138 | - * |
|
| 139 | - * @param string $str |
|
| 140 | - * @return int|string |
|
| 141 | - */ |
|
| 142 | - protected function toBytes($str) |
|
| 143 | - { |
|
| 144 | - $val = trim($str); |
|
| 145 | - $last = strtolower($str[strlen($str) - 1]); |
|
| 146 | - switch ($last) { |
|
| 147 | - case 'g': |
|
| 148 | - $val *= 1024; |
|
| 149 | - case 'm': |
|
| 150 | - $val *= 1024; |
|
| 151 | - case 'k': |
|
| 152 | - $val *= 1024; |
|
| 153 | - } |
|
| 154 | - return $val; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Return a file name given an uploaded file |
|
| 159 | - * |
|
| 160 | - * @param UploadedFileInterface $uploadedFile |
|
| 161 | - * @return string |
|
| 162 | - */ |
|
| 163 | - public function getFileName(UploadedFileInterface $uploadedFile) |
|
| 164 | - { |
|
| 165 | - $pathInfo = pathinfo($uploadedFile->getOriginalName()); |
|
| 166 | - $fileName = $this->sanitizeFileName($pathInfo['filename']); |
|
| 167 | - $fileNameWithExtension = $fileName; |
|
| 168 | - if (!empty($pathInfo['extension'])) { |
|
| 169 | - $fileNameWithExtension = sprintf('%s.%s', $fileName, $pathInfo['extension']); |
|
| 170 | - } |
|
| 171 | - return $fileNameWithExtension; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Check whether the file size does not exceed the allowed limit |
|
| 176 | - * |
|
| 177 | - * @param int $size |
|
| 178 | - */ |
|
| 179 | - public function checkFileSize($size) |
|
| 180 | - { |
|
| 181 | - if ($size == 0) { |
|
| 182 | - $this->throwException('File is empty'); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ($size > $this->sizeLimit) { |
|
| 186 | - $this->throwException('File is too large'); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Check whether the file is allowed |
|
| 192 | - * |
|
| 193 | - * @param string $fileName |
|
| 194 | - */ |
|
| 195 | - public function checkFileAllowed($fileName) |
|
| 196 | - { |
|
| 197 | - $isAllowed = $this->checkFileExtensionPermission($fileName); |
|
| 198 | - if (!$isAllowed) { |
|
| 199 | - $these = PermissionUtility::getInstance()->getAllowedExtensionList(); |
|
| 200 | - $this->throwException('File has an invalid extension, it should be one of ' . $these . '.'); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * If the fileName is given, check it against the |
|
| 206 | - * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed |
|
| 207 | - * |
|
| 208 | - * @see \TYPO3\CMS\Core\Resource\ResourceStorage->checkFileExtensionPermission($fileName); |
|
| 209 | - * @param string $fileName Full filename |
|
| 210 | - * @return boolean true if extension/filename is allowed |
|
| 211 | - */ |
|
| 212 | - public function checkFileExtensionPermission($fileName) |
|
| 213 | - { |
|
| 214 | - $isAllowed = GeneralUtility::verifyFilenameAgainstDenyPattern($fileName); |
|
| 215 | - if ($isAllowed) { |
|
| 216 | - $fileInfo = GeneralUtility::split_fileref($fileName); |
|
| 217 | - // Set up the permissions for the file extension |
|
| 218 | - $fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']; |
|
| 219 | - $fileExtensionPermissions['allow'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['allow'])); |
|
| 220 | - $fileExtensionPermissions['deny'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['deny'])); |
|
| 221 | - $fileExtension = strtolower($fileInfo['fileext']); |
|
| 222 | - if ($fileExtension !== '') { |
|
| 223 | - // If the extension is found amongst the allowed types, we return true immediately |
|
| 224 | - if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) { |
|
| 225 | - return true; |
|
| 226 | - } |
|
| 227 | - // If the extension is found amongst the denied types, we return false immediately |
|
| 228 | - if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - // If no match we return true |
|
| 232 | - return true; |
|
| 233 | - } else { |
|
| 234 | - if ($fileExtensionPermissions['allow'] === '*') { |
|
| 235 | - return true; |
|
| 236 | - } |
|
| 237 | - if ($fileExtensionPermissions['deny'] === '*') { |
|
| 238 | - return false; |
|
| 239 | - } |
|
| 240 | - return true; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Sanitize the file name for the web. |
|
| 248 | - * It has been noticed issues when letting done this work by FAL. Give it a little hand. |
|
| 249 | - * |
|
| 250 | - * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L252 |
|
| 251 | - * @param string $fileName |
|
| 252 | - * @param string $slug |
|
| 253 | - * @param string $extra |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - public function sanitizeFileName($fileName, $slug = '-', $extra = null) |
|
| 257 | - { |
|
| 258 | - return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Remove accent from a string |
|
| 263 | - * |
|
| 264 | - * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297 |
|
| 265 | - * @param $string |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - protected function unAccent($string) |
|
| 269 | - { |
|
| 270 | - $searches = array('ç', 'æ', 'œ', 'á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', 'å', 'e', 'i', 'ø', 'u'); |
|
| 271 | - $replaces = array('c', 'ae', 'oe', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'); |
|
| 272 | - $sanitizedString = str_replace($searches, $replaces, $string); |
|
| 273 | - |
|
| 274 | - if (extension_loaded('intl') === true) { |
|
| 275 | - $sanitizedString = \Normalizer::normalize($sanitizedString, \Normalizer::FORM_KD); |
|
| 276 | - } |
|
| 277 | - return $sanitizedString; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * @throws FailedFileUploadException |
|
| 282 | - * @param string $message |
|
| 283 | - */ |
|
| 284 | - protected function throwException($message) |
|
| 285 | - { |
|
| 286 | - throw new FailedFileUploadException($message, 1357510420); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Initialize Upload Folder. |
|
| 291 | - * |
|
| 292 | - * @return void |
|
| 293 | - */ |
|
| 294 | - protected function initializeUploadFolder() |
|
| 295 | - { |
|
| 296 | - $this->uploadFolder = PATH_site . self::UPLOAD_FOLDER; |
|
| 297 | - |
|
| 298 | - // Initialize the upload folder for file transfer and create it if not yet existing |
|
| 299 | - if (!file_exists($this->uploadFolder)) { |
|
| 300 | - GeneralUtility::mkdir($this->uploadFolder); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // Check whether the upload folder is writable |
|
| 304 | - if (!is_writable($this->uploadFolder)) { |
|
| 305 | - $this->throwException("Server error. Upload directory isn't writable."); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * @return int|null|string |
|
| 311 | - */ |
|
| 312 | - public function getSizeLimit() |
|
| 313 | - { |
|
| 314 | - return $this->sizeLimit; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param int|null|string $sizeLimit |
|
| 319 | - * @return $this |
|
| 320 | - */ |
|
| 321 | - public function setSizeLimit($sizeLimit) |
|
| 322 | - { |
|
| 323 | - $this->sizeLimit = $sizeLimit; |
|
| 324 | - return $this; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @return string |
|
| 329 | - */ |
|
| 330 | - public function getUploadFolder() |
|
| 331 | - { |
|
| 332 | - return $this->uploadFolder; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * @param string $uploadFolder |
|
| 337 | - * @return $this |
|
| 338 | - */ |
|
| 339 | - public function setUploadFolder($uploadFolder) |
|
| 340 | - { |
|
| 341 | - $this->uploadFolder = $uploadFolder; |
|
| 342 | - return $this; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @return string |
|
| 347 | - */ |
|
| 348 | - public function getInputName() |
|
| 349 | - { |
|
| 350 | - return $this->inputName; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @param string $inputName |
|
| 355 | - * @return $this |
|
| 356 | - */ |
|
| 357 | - public function setInputName($inputName) |
|
| 358 | - { |
|
| 359 | - $this->inputName = $inputName; |
|
| 360 | - return $this; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * @return \TYPO3\CMS\Core\Resource\ResourceStorage |
|
| 365 | - */ |
|
| 366 | - public function getStorage() |
|
| 367 | - { |
|
| 368 | - return $this->storage; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
| 373 | - * @return $this |
|
| 374 | - */ |
|
| 375 | - public function setStorage($storage) |
|
| 376 | - { |
|
| 377 | - $this->storage = $storage; |
|
| 378 | - return $this; |
|
| 379 | - } |
|
| 23 | + const UPLOAD_FOLDER = 'typo3temp/pics'; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var int|null|string |
|
| 27 | + */ |
|
| 28 | + protected $sizeLimit; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + protected $uploadFolder; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var FormUtility |
|
| 37 | + */ |
|
| 38 | + protected $formUtility; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var \TYPO3\CMS\Core\Resource\ResourceStorage |
|
| 42 | + */ |
|
| 43 | + protected $storage; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Name of the file input in the DOM. |
|
| 47 | + * |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | + protected $inputName = 'qqfile'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
| 54 | + * @return UploadManager |
|
| 55 | + */ |
|
| 56 | + function __construct($storage = null) |
|
| 57 | + { |
|
| 58 | + |
|
| 59 | + $this->initializeUploadFolder(); |
|
| 60 | + |
|
| 61 | + // max file size in bytes |
|
| 62 | + $this->sizeLimit = GeneralUtility::getMaxUploadFileSize() * 1024; |
|
| 63 | + $this->checkServerSettings(); |
|
| 64 | + |
|
| 65 | + $this->formUtility = FormUtility::getInstance(); |
|
| 66 | + $this->storage = $storage; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Handle the uploaded file. |
|
| 71 | + * |
|
| 72 | + * @return UploadedFileInterface |
|
| 73 | + */ |
|
| 74 | + public function handleUpload() |
|
| 75 | + { |
|
| 76 | + |
|
| 77 | + /** @var $uploadedFile UploadedFileInterface */ |
|
| 78 | + $uploadedFile = false; |
|
| 79 | + if ($this->formUtility->isMultiparted()) { |
|
| 80 | + |
|
| 81 | + // Default case |
|
| 82 | + $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\MultipartedFile::class); |
|
| 83 | + } elseif ($this->formUtility->isOctetStreamed()) { |
|
| 84 | + |
|
| 85 | + // Fine Upload plugin would use it if forceEncoded = false and paramsInBody = false |
|
| 86 | + $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\StreamedFile::class); |
|
| 87 | + } elseif ($this->formUtility->isUrlEncoded()) { |
|
| 88 | + |
|
| 89 | + // Used for image resizing in BE |
|
| 90 | + $uploadedFile = GeneralUtility::makeInstance(\Fab\Media\FileUpload\Base64File::class); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if (!$uploadedFile) { |
|
| 94 | + $this->throwException('Could not instantiate an upload object... No file was uploaded?'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $fileName = $this->getFileName($uploadedFile); |
|
| 98 | + |
|
| 99 | + $this->checkFileSize($uploadedFile->getSize()); |
|
| 100 | + $this->checkFileAllowed($fileName); |
|
| 101 | + |
|
| 102 | + $saved = $uploadedFile->setInputName($this->inputName) |
|
| 103 | + ->setUploadFolder($this->uploadFolder) |
|
| 104 | + ->setName($fileName) |
|
| 105 | + ->save(); |
|
| 106 | + |
|
| 107 | + if (!$saved) { |
|
| 108 | + $this->throwException('Could not save uploaded file. The upload was cancelled, or server error encountered'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Optimize file if the uploaded file is an image. |
|
| 112 | + if ($uploadedFile->getType() == \TYPO3\CMS\Core\Resource\File::FILETYPE_IMAGE) { |
|
| 113 | + $uploadedFile = ImageOptimizer::getInstance($this->storage)->optimize($uploadedFile); |
|
| 114 | + } |
|
| 115 | + return $uploadedFile; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Internal function that checks if server's may sizes match the |
|
| 120 | + * object's maximum size for uploads. |
|
| 121 | + * |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + protected function checkServerSettings() |
|
| 125 | + { |
|
| 126 | + $postSize = $this->toBytes(ini_get('post_max_size')); |
|
| 127 | + |
|
| 128 | + $uploadSize = $this->toBytes(ini_get('upload_max_filesize')); |
|
| 129 | + |
|
| 130 | + if ($postSize < $this->sizeLimit || $uploadSize < $this->sizeLimit) { |
|
| 131 | + $size = max(1, $this->sizeLimit / 1024 / 1024) . 'M'; |
|
| 132 | + $this->throwException('increase post_max_size and upload_max_filesize to ' . $size); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Convert a given size with units to bytes. |
|
| 138 | + * |
|
| 139 | + * @param string $str |
|
| 140 | + * @return int|string |
|
| 141 | + */ |
|
| 142 | + protected function toBytes($str) |
|
| 143 | + { |
|
| 144 | + $val = trim($str); |
|
| 145 | + $last = strtolower($str[strlen($str) - 1]); |
|
| 146 | + switch ($last) { |
|
| 147 | + case 'g': |
|
| 148 | + $val *= 1024; |
|
| 149 | + case 'm': |
|
| 150 | + $val *= 1024; |
|
| 151 | + case 'k': |
|
| 152 | + $val *= 1024; |
|
| 153 | + } |
|
| 154 | + return $val; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Return a file name given an uploaded file |
|
| 159 | + * |
|
| 160 | + * @param UploadedFileInterface $uploadedFile |
|
| 161 | + * @return string |
|
| 162 | + */ |
|
| 163 | + public function getFileName(UploadedFileInterface $uploadedFile) |
|
| 164 | + { |
|
| 165 | + $pathInfo = pathinfo($uploadedFile->getOriginalName()); |
|
| 166 | + $fileName = $this->sanitizeFileName($pathInfo['filename']); |
|
| 167 | + $fileNameWithExtension = $fileName; |
|
| 168 | + if (!empty($pathInfo['extension'])) { |
|
| 169 | + $fileNameWithExtension = sprintf('%s.%s', $fileName, $pathInfo['extension']); |
|
| 170 | + } |
|
| 171 | + return $fileNameWithExtension; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Check whether the file size does not exceed the allowed limit |
|
| 176 | + * |
|
| 177 | + * @param int $size |
|
| 178 | + */ |
|
| 179 | + public function checkFileSize($size) |
|
| 180 | + { |
|
| 181 | + if ($size == 0) { |
|
| 182 | + $this->throwException('File is empty'); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ($size > $this->sizeLimit) { |
|
| 186 | + $this->throwException('File is too large'); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Check whether the file is allowed |
|
| 192 | + * |
|
| 193 | + * @param string $fileName |
|
| 194 | + */ |
|
| 195 | + public function checkFileAllowed($fileName) |
|
| 196 | + { |
|
| 197 | + $isAllowed = $this->checkFileExtensionPermission($fileName); |
|
| 198 | + if (!$isAllowed) { |
|
| 199 | + $these = PermissionUtility::getInstance()->getAllowedExtensionList(); |
|
| 200 | + $this->throwException('File has an invalid extension, it should be one of ' . $these . '.'); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * If the fileName is given, check it against the |
|
| 206 | + * TYPO3_CONF_VARS[BE][fileDenyPattern] + and if the file extension is allowed |
|
| 207 | + * |
|
| 208 | + * @see \TYPO3\CMS\Core\Resource\ResourceStorage->checkFileExtensionPermission($fileName); |
|
| 209 | + * @param string $fileName Full filename |
|
| 210 | + * @return boolean true if extension/filename is allowed |
|
| 211 | + */ |
|
| 212 | + public function checkFileExtensionPermission($fileName) |
|
| 213 | + { |
|
| 214 | + $isAllowed = GeneralUtility::verifyFilenameAgainstDenyPattern($fileName); |
|
| 215 | + if ($isAllowed) { |
|
| 216 | + $fileInfo = GeneralUtility::split_fileref($fileName); |
|
| 217 | + // Set up the permissions for the file extension |
|
| 218 | + $fileExtensionPermissions = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']['webspace']; |
|
| 219 | + $fileExtensionPermissions['allow'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['allow'])); |
|
| 220 | + $fileExtensionPermissions['deny'] = GeneralUtility::uniqueList(strtolower($fileExtensionPermissions['deny'])); |
|
| 221 | + $fileExtension = strtolower($fileInfo['fileext']); |
|
| 222 | + if ($fileExtension !== '') { |
|
| 223 | + // If the extension is found amongst the allowed types, we return true immediately |
|
| 224 | + if ($fileExtensionPermissions['allow'] === '*' || GeneralUtility::inList($fileExtensionPermissions['allow'], $fileExtension)) { |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 227 | + // If the extension is found amongst the denied types, we return false immediately |
|
| 228 | + if ($fileExtensionPermissions['deny'] === '*' || GeneralUtility::inList($fileExtensionPermissions['deny'], $fileExtension)) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + // If no match we return true |
|
| 232 | + return true; |
|
| 233 | + } else { |
|
| 234 | + if ($fileExtensionPermissions['allow'] === '*') { |
|
| 235 | + return true; |
|
| 236 | + } |
|
| 237 | + if ($fileExtensionPermissions['deny'] === '*') { |
|
| 238 | + return false; |
|
| 239 | + } |
|
| 240 | + return true; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Sanitize the file name for the web. |
|
| 248 | + * It has been noticed issues when letting done this work by FAL. Give it a little hand. |
|
| 249 | + * |
|
| 250 | + * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L252 |
|
| 251 | + * @param string $fileName |
|
| 252 | + * @param string $slug |
|
| 253 | + * @param string $extra |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + public function sanitizeFileName($fileName, $slug = '-', $extra = null) |
|
| 257 | + { |
|
| 258 | + return trim(preg_replace('~[^0-9a-z_' . preg_quote($extra, '~') . ']+~i', $slug, $this->unAccent($fileName)), $slug); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Remove accent from a string |
|
| 263 | + * |
|
| 264 | + * @see https://github.com/alixaxel/phunction/blob/master/phunction/Text.php#L297 |
|
| 265 | + * @param $string |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + protected function unAccent($string) |
|
| 269 | + { |
|
| 270 | + $searches = array('ç', 'æ', 'œ', 'á', 'é', 'í', 'ó', 'ú', 'à', 'è', 'ì', 'ò', 'ù', 'ä', 'ë', 'ï', 'ö', 'ü', 'ÿ', 'â', 'ê', 'î', 'ô', 'û', 'å', 'e', 'i', 'ø', 'u'); |
|
| 271 | + $replaces = array('c', 'ae', 'oe', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u', 'y', 'a', 'e', 'i', 'o', 'u', 'a', 'e', 'i', 'o', 'u'); |
|
| 272 | + $sanitizedString = str_replace($searches, $replaces, $string); |
|
| 273 | + |
|
| 274 | + if (extension_loaded('intl') === true) { |
|
| 275 | + $sanitizedString = \Normalizer::normalize($sanitizedString, \Normalizer::FORM_KD); |
|
| 276 | + } |
|
| 277 | + return $sanitizedString; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * @throws FailedFileUploadException |
|
| 282 | + * @param string $message |
|
| 283 | + */ |
|
| 284 | + protected function throwException($message) |
|
| 285 | + { |
|
| 286 | + throw new FailedFileUploadException($message, 1357510420); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Initialize Upload Folder. |
|
| 291 | + * |
|
| 292 | + * @return void |
|
| 293 | + */ |
|
| 294 | + protected function initializeUploadFolder() |
|
| 295 | + { |
|
| 296 | + $this->uploadFolder = PATH_site . self::UPLOAD_FOLDER; |
|
| 297 | + |
|
| 298 | + // Initialize the upload folder for file transfer and create it if not yet existing |
|
| 299 | + if (!file_exists($this->uploadFolder)) { |
|
| 300 | + GeneralUtility::mkdir($this->uploadFolder); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // Check whether the upload folder is writable |
|
| 304 | + if (!is_writable($this->uploadFolder)) { |
|
| 305 | + $this->throwException("Server error. Upload directory isn't writable."); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * @return int|null|string |
|
| 311 | + */ |
|
| 312 | + public function getSizeLimit() |
|
| 313 | + { |
|
| 314 | + return $this->sizeLimit; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param int|null|string $sizeLimit |
|
| 319 | + * @return $this |
|
| 320 | + */ |
|
| 321 | + public function setSizeLimit($sizeLimit) |
|
| 322 | + { |
|
| 323 | + $this->sizeLimit = $sizeLimit; |
|
| 324 | + return $this; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @return string |
|
| 329 | + */ |
|
| 330 | + public function getUploadFolder() |
|
| 331 | + { |
|
| 332 | + return $this->uploadFolder; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * @param string $uploadFolder |
|
| 337 | + * @return $this |
|
| 338 | + */ |
|
| 339 | + public function setUploadFolder($uploadFolder) |
|
| 340 | + { |
|
| 341 | + $this->uploadFolder = $uploadFolder; |
|
| 342 | + return $this; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @return string |
|
| 347 | + */ |
|
| 348 | + public function getInputName() |
|
| 349 | + { |
|
| 350 | + return $this->inputName; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @param string $inputName |
|
| 355 | + * @return $this |
|
| 356 | + */ |
|
| 357 | + public function setInputName($inputName) |
|
| 358 | + { |
|
| 359 | + $this->inputName = $inputName; |
|
| 360 | + return $this; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * @return \TYPO3\CMS\Core\Resource\ResourceStorage |
|
| 365 | + */ |
|
| 366 | + public function getStorage() |
|
| 367 | + { |
|
| 368 | + return $this->storage; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @param \TYPO3\CMS\Core\Resource\ResourceStorage $storage |
|
| 373 | + * @return $this |
|
| 374 | + */ |
|
| 375 | + public function setStorage($storage) |
|
| 376 | + { |
|
| 377 | + $this->storage = $storage; |
|
| 378 | + return $this; |
|
| 379 | + } |
|
| 380 | 380 | |
| 381 | 381 | } |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | * Sanitize an id |
| 57 | 57 | * |
| 58 | 58 | * @param string $input |
| 59 | - * @return mixed |
|
| 59 | + * @return string |
|
| 60 | 60 | */ |
| 61 | 61 | protected function sanitizeId($input) |
| 62 | 62 | { |
@@ -16,57 +16,57 @@ |
||
| 16 | 16 | class DomElement implements SingletonInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Returns a class instance |
|
| 21 | - * |
|
| 22 | - * @return \Fab\Media\Utility\DomElement|object |
|
| 23 | - */ |
|
| 24 | - static public function getInstance() |
|
| 25 | - { |
|
| 26 | - return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Fab\Media\Utility\DomElement::class); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * Returns a class instance |
|
| 21 | + * |
|
| 22 | + * @return \Fab\Media\Utility\DomElement|object |
|
| 23 | + */ |
|
| 24 | + static public function getInstance() |
|
| 25 | + { |
|
| 26 | + return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\Fab\Media\Utility\DomElement::class); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Format an id given an input string |
|
| 31 | - * |
|
| 32 | - * @param string $input |
|
| 33 | - * @return string |
|
| 34 | - */ |
|
| 35 | - public function formatId($input) |
|
| 36 | - { |
|
| 29 | + /** |
|
| 30 | + * Format an id given an input string |
|
| 31 | + * |
|
| 32 | + * @param string $input |
|
| 33 | + * @return string |
|
| 34 | + */ |
|
| 35 | + public function formatId($input) |
|
| 36 | + { |
|
| 37 | 37 | |
| 38 | - // remove the capital letter from the id |
|
| 39 | - $segments = preg_split('/(?=[A-Z])/', $input); |
|
| 40 | - $segments = array_map('strtolower', $segments); |
|
| 41 | - if ($segments[0] == '') { |
|
| 42 | - array_shift($segments); |
|
| 43 | - } |
|
| 44 | - $result = implode('-', $segments); |
|
| 38 | + // remove the capital letter from the id |
|
| 39 | + $segments = preg_split('/(?=[A-Z])/', $input); |
|
| 40 | + $segments = array_map('strtolower', $segments); |
|
| 41 | + if ($segments[0] == '') { |
|
| 42 | + array_shift($segments); |
|
| 43 | + } |
|
| 44 | + $result = implode('-', $segments); |
|
| 45 | 45 | |
| 46 | - return $this->sanitizeId($result); |
|
| 47 | - } |
|
| 46 | + return $this->sanitizeId($result); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Sanitize an id |
|
| 51 | - * |
|
| 52 | - * @param string $input |
|
| 53 | - * @return mixed |
|
| 54 | - */ |
|
| 55 | - protected function sanitizeId($input) |
|
| 56 | - { |
|
| 49 | + /** |
|
| 50 | + * Sanitize an id |
|
| 51 | + * |
|
| 52 | + * @param string $input |
|
| 53 | + * @return mixed |
|
| 54 | + */ |
|
| 55 | + protected function sanitizeId($input) |
|
| 56 | + { |
|
| 57 | 57 | |
| 58 | - // remove the track of possible namespace |
|
| 59 | - $searches[] = ' '; |
|
| 60 | - $searches[] = '_'; |
|
| 61 | - $searches[] = '--'; |
|
| 62 | - $searches[] = '['; |
|
| 63 | - $searches[] = ']'; |
|
| 64 | - $replaces[] = '-'; |
|
| 65 | - $replaces[] = '-'; |
|
| 66 | - $replaces[] = '-'; |
|
| 67 | - $replaces[] = '-'; |
|
| 68 | - $replaces[] = ''; |
|
| 69 | - return str_replace($searches, $replaces, strtolower($input)); |
|
| 70 | - } |
|
| 58 | + // remove the track of possible namespace |
|
| 59 | + $searches[] = ' '; |
|
| 60 | + $searches[] = '_'; |
|
| 61 | + $searches[] = '--'; |
|
| 62 | + $searches[] = '['; |
|
| 63 | + $searches[] = ']'; |
|
| 64 | + $replaces[] = '-'; |
|
| 65 | + $replaces[] = '-'; |
|
| 66 | + $replaces[] = '-'; |
|
| 67 | + $replaces[] = '-'; |
|
| 68 | + $replaces[] = ''; |
|
| 69 | + return str_replace($searches, $replaces, strtolower($input)); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | 72 | } |
@@ -16,7 +16,6 @@ |
||
| 16 | 16 | |
| 17 | 17 | use Fab\Media\Module\MediaModule; |
| 18 | 18 | use TYPO3\CMS\Core\Resource\Folder; |
| 19 | -use TYPO3\CMS\Core\Resource\ResourceFactory; |
|
| 20 | 19 | use TYPO3\CMS\Core\Resource\Utility\ListUtility; |
| 21 | 20 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
| 22 | 21 | use Fab\Vidi\View\AbstractComponentView; |
@@ -21,59 +21,59 @@ |
||
| 21 | 21 | class SelectedFolderInfo extends AbstractComponentView |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - public $notAllowedMountPoints = []; |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + public $notAllowedMountPoints = []; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Renders a button for uploading assets. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function render() |
|
| 35 | - { |
|
| 29 | + /** |
|
| 30 | + * Renders a button for uploading assets. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function render() |
|
| 35 | + { |
|
| 36 | 36 | |
| 37 | - $result = ''; |
|
| 38 | - if ($this->getMediaModule()->hasFolderTree()) { |
|
| 37 | + $result = ''; |
|
| 38 | + if ($this->getMediaModule()->hasFolderTree()) { |
|
| 39 | 39 | |
| 40 | - $folder = $this->getMediaModule()->getCurrentFolder(); |
|
| 41 | - $result = sprintf('<h1>%s</h1>', $this->getFolderName($folder)); |
|
| 42 | - } |
|
| 40 | + $folder = $this->getMediaModule()->getCurrentFolder(); |
|
| 41 | + $result = sprintf('<h1>%s</h1>', $this->getFolderName($folder)); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return $result; |
|
| 45 | - } |
|
| 44 | + return $result; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get main headline based on active folder or storage for backend module |
|
| 49 | - * |
|
| 50 | - * Folder names are resolved to their special names like done in the tree view. |
|
| 51 | - * |
|
| 52 | - * @param Folder $folder |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - protected function getFolderName(Folder $folder) |
|
| 56 | - { |
|
| 57 | - $name = $folder->getName(); |
|
| 58 | - if ($name === '') { |
|
| 59 | - // Show storage name on storage root |
|
| 60 | - if ($folder->getIdentifier() === '/') { |
|
| 61 | - $name = $folder->getStorage()->getName(); |
|
| 62 | - } |
|
| 63 | - } else { |
|
| 64 | - $name = key(ListUtility::resolveSpecialFolderNames( |
|
| 65 | - array($name => $folder) |
|
| 66 | - )); |
|
| 67 | - } |
|
| 68 | - return $name; |
|
| 69 | - } |
|
| 47 | + /** |
|
| 48 | + * Get main headline based on active folder or storage for backend module |
|
| 49 | + * |
|
| 50 | + * Folder names are resolved to their special names like done in the tree view. |
|
| 51 | + * |
|
| 52 | + * @param Folder $folder |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + protected function getFolderName(Folder $folder) |
|
| 56 | + { |
|
| 57 | + $name = $folder->getName(); |
|
| 58 | + if ($name === '') { |
|
| 59 | + // Show storage name on storage root |
|
| 60 | + if ($folder->getIdentifier() === '/') { |
|
| 61 | + $name = $folder->getStorage()->getName(); |
|
| 62 | + } |
|
| 63 | + } else { |
|
| 64 | + $name = key(ListUtility::resolveSpecialFolderNames( |
|
| 65 | + array($name => $folder) |
|
| 66 | + )); |
|
| 67 | + } |
|
| 68 | + return $name; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return MediaModule|object |
|
| 73 | - */ |
|
| 74 | - protected function getMediaModule() |
|
| 75 | - { |
|
| 76 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 77 | - } |
|
| 71 | + /** |
|
| 72 | + * @return MediaModule|object |
|
| 73 | + */ |
|
| 74 | + protected function getMediaModule() |
|
| 75 | + { |
|
| 76 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | - * @return boolean |
|
| 82 | + * @return boolean|null |
|
| 83 | 83 | */ |
| 84 | 84 | protected function configureStorage() |
| 85 | 85 | { |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | - * @return boolean |
|
| 305 | + * @return integer |
|
| 306 | 306 | */ |
| 307 | 307 | protected function canBeInitializedSilently() |
| 308 | 308 | { |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $storage = $this->getMediaModule()->getCurrentStorage(); |
| 102 | - $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 102 | + $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = '.$storage->getUid(), $values); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | protected function getWarmUpSemaphoreFile() |
| 117 | 117 | { |
| 118 | - return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 118 | + return PATH_site.'typo3temp/.media_cache_warmed_up'; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | */ |
| 262 | 262 | protected function fetchMountPoint($identifier) |
| 263 | 263 | { |
| 264 | - return $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_filemounts', 'uid = ' . $identifier); |
|
| 264 | + return $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_filemounts', 'uid = '.$identifier); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -19,142 +19,142 @@ discard block |
||
| 19 | 19 | class ConfigurationWarning extends AbstractComponentView |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $notAllowedMountPoints = []; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Renders a button for uploading assets. |
|
| 29 | - * |
|
| 30 | - * @return string |
|
| 31 | - */ |
|
| 32 | - public function render() |
|
| 33 | - { |
|
| 34 | - |
|
| 35 | - $result = ''; |
|
| 36 | - |
|
| 37 | - // Check whether storage is configured or not. |
|
| 38 | - if ($this->checkStorageNotConfigured()) { |
|
| 39 | - $this->configureStorage(); |
|
| 40 | - $result .= $this->formatMessageForStorageConfigured(); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // Check whether storage is online or not. |
|
| 44 | - if ($this->checkStorageOffline()) { |
|
| 45 | - $result .= $this->formatMessageForStorageOffline(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // Check all mount points of the storage are available |
|
| 49 | - if (!$this->checkMountPoints()) { |
|
| 50 | - $result .= $this->formatMessageForMountPoints(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Check all mount points of the storage are available |
|
| 54 | - if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
| 55 | - if ($this->canBeInitializedSilently() < 2000) { |
|
| 56 | - $numberOfFiles = $this->getCacheService()->warmUp(); |
|
| 57 | - $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
| 58 | - touch($this->getWarmUpSemaphoreFile()); |
|
| 59 | - } else { |
|
| 60 | - $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - return $result; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @return \Fab\Media\Cache\CacheService|object |
|
| 69 | - */ |
|
| 70 | - protected function getCacheService() |
|
| 71 | - { |
|
| 72 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @return boolean |
|
| 77 | - */ |
|
| 78 | - protected function configureStorage() |
|
| 79 | - { |
|
| 80 | - $tableName = 'sys_file_storage'; |
|
| 81 | - $fields = array( |
|
| 82 | - 'maximum_dimension_original_image', |
|
| 83 | - 'extension_allowed_file_type_1', |
|
| 84 | - 'extension_allowed_file_type_2', |
|
| 85 | - 'extension_allowed_file_type_3', |
|
| 86 | - 'extension_allowed_file_type_4', |
|
| 87 | - 'extension_allowed_file_type_5', |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - $values = []; |
|
| 91 | - foreach ($fields as $field) { |
|
| 92 | - $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 96 | - $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @return bool |
|
| 101 | - */ |
|
| 102 | - protected function hasBeenWarmedUp() |
|
| 103 | - { |
|
| 104 | - return is_file(($this->getWarmUpSemaphoreFile())); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - protected function getWarmUpSemaphoreFile() |
|
| 111 | - { |
|
| 112 | - return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Check whether the storage is correctly configured. |
|
| 117 | - * |
|
| 118 | - * @return boolean |
|
| 119 | - */ |
|
| 120 | - protected function checkStorageNotConfigured() |
|
| 121 | - { |
|
| 122 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 123 | - $storageRecord = $currentStorage->getStorageRecord(); |
|
| 124 | - |
|
| 125 | - // Take the storage fields and check whether some data was initialized. |
|
| 126 | - $fields = array( |
|
| 127 | - 'extension_allowed_file_type_1', |
|
| 128 | - 'extension_allowed_file_type_2', |
|
| 129 | - 'extension_allowed_file_type_3', |
|
| 130 | - 'extension_allowed_file_type_4', |
|
| 131 | - 'extension_allowed_file_type_5', |
|
| 132 | - ); |
|
| 133 | - |
|
| 134 | - $result = true; |
|
| 135 | - foreach ($fields as $fieldName) { |
|
| 136 | - // true means the storage has data and thus was configured / saved once. |
|
| 137 | - if (!empty($storageRecord[$fieldName])) { |
|
| 138 | - $result = false; |
|
| 139 | - break; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - return $result; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Format a message whenever the storage is offline. |
|
| 147 | - * |
|
| 148 | - * @return string |
|
| 149 | - */ |
|
| 150 | - protected function formatMessageForStorageConfigured() |
|
| 151 | - { |
|
| 152 | - |
|
| 153 | - // TODO: after dropping typo3 7.6 support, remove class: typo3-message message-warning message-header message-body |
|
| 154 | - |
|
| 155 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 156 | - |
|
| 157 | - $result = <<< EOF |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $notAllowedMountPoints = []; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Renders a button for uploading assets. |
|
| 29 | + * |
|
| 30 | + * @return string |
|
| 31 | + */ |
|
| 32 | + public function render() |
|
| 33 | + { |
|
| 34 | + |
|
| 35 | + $result = ''; |
|
| 36 | + |
|
| 37 | + // Check whether storage is configured or not. |
|
| 38 | + if ($this->checkStorageNotConfigured()) { |
|
| 39 | + $this->configureStorage(); |
|
| 40 | + $result .= $this->formatMessageForStorageConfigured(); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // Check whether storage is online or not. |
|
| 44 | + if ($this->checkStorageOffline()) { |
|
| 45 | + $result .= $this->formatMessageForStorageOffline(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // Check all mount points of the storage are available |
|
| 49 | + if (!$this->checkMountPoints()) { |
|
| 50 | + $result .= $this->formatMessageForMountPoints(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Check all mount points of the storage are available |
|
| 54 | + if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
| 55 | + if ($this->canBeInitializedSilently() < 2000) { |
|
| 56 | + $numberOfFiles = $this->getCacheService()->warmUp(); |
|
| 57 | + $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
| 58 | + touch($this->getWarmUpSemaphoreFile()); |
|
| 59 | + } else { |
|
| 60 | + $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + return $result; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @return \Fab\Media\Cache\CacheService|object |
|
| 69 | + */ |
|
| 70 | + protected function getCacheService() |
|
| 71 | + { |
|
| 72 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @return boolean |
|
| 77 | + */ |
|
| 78 | + protected function configureStorage() |
|
| 79 | + { |
|
| 80 | + $tableName = 'sys_file_storage'; |
|
| 81 | + $fields = array( |
|
| 82 | + 'maximum_dimension_original_image', |
|
| 83 | + 'extension_allowed_file_type_1', |
|
| 84 | + 'extension_allowed_file_type_2', |
|
| 85 | + 'extension_allowed_file_type_3', |
|
| 86 | + 'extension_allowed_file_type_4', |
|
| 87 | + 'extension_allowed_file_type_5', |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + $values = []; |
|
| 91 | + foreach ($fields as $field) { |
|
| 92 | + $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 96 | + $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @return bool |
|
| 101 | + */ |
|
| 102 | + protected function hasBeenWarmedUp() |
|
| 103 | + { |
|
| 104 | + return is_file(($this->getWarmUpSemaphoreFile())); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + protected function getWarmUpSemaphoreFile() |
|
| 111 | + { |
|
| 112 | + return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Check whether the storage is correctly configured. |
|
| 117 | + * |
|
| 118 | + * @return boolean |
|
| 119 | + */ |
|
| 120 | + protected function checkStorageNotConfigured() |
|
| 121 | + { |
|
| 122 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 123 | + $storageRecord = $currentStorage->getStorageRecord(); |
|
| 124 | + |
|
| 125 | + // Take the storage fields and check whether some data was initialized. |
|
| 126 | + $fields = array( |
|
| 127 | + 'extension_allowed_file_type_1', |
|
| 128 | + 'extension_allowed_file_type_2', |
|
| 129 | + 'extension_allowed_file_type_3', |
|
| 130 | + 'extension_allowed_file_type_4', |
|
| 131 | + 'extension_allowed_file_type_5', |
|
| 132 | + ); |
|
| 133 | + |
|
| 134 | + $result = true; |
|
| 135 | + foreach ($fields as $fieldName) { |
|
| 136 | + // true means the storage has data and thus was configured / saved once. |
|
| 137 | + if (!empty($storageRecord[$fieldName])) { |
|
| 138 | + $result = false; |
|
| 139 | + break; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + return $result; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Format a message whenever the storage is offline. |
|
| 147 | + * |
|
| 148 | + * @return string |
|
| 149 | + */ |
|
| 150 | + protected function formatMessageForStorageConfigured() |
|
| 151 | + { |
|
| 152 | + |
|
| 153 | + // TODO: after dropping typo3 7.6 support, remove class: typo3-message message-warning message-header message-body |
|
| 154 | + |
|
| 155 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 156 | + |
|
| 157 | + $result = <<< EOF |
|
| 158 | 158 | <div class="typo3-message message-information alert alert-info"> |
| 159 | 159 | <div class="message-header alert-title"> |
| 160 | 160 | Storage has been configured. |
@@ -167,31 +167,31 @@ discard block |
||
| 167 | 167 | </div> |
| 168 | 168 | EOF; |
| 169 | 169 | |
| 170 | - return $result; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Check whether the storage is online or not. |
|
| 175 | - * |
|
| 176 | - * @return boolean |
|
| 177 | - */ |
|
| 178 | - protected function checkStorageOffline() |
|
| 179 | - { |
|
| 180 | - return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Format a message whenever the storage is offline. |
|
| 185 | - * |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 188 | - protected function formatMessageForStorageOffline() |
|
| 189 | - { |
|
| 190 | - // TODO: after dropping typo3 7.6 support, remove class: typo3-message message-warning message-header message-body |
|
| 191 | - |
|
| 192 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 193 | - |
|
| 194 | - $result = <<< EOF |
|
| 170 | + return $result; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Check whether the storage is online or not. |
|
| 175 | + * |
|
| 176 | + * @return boolean |
|
| 177 | + */ |
|
| 178 | + protected function checkStorageOffline() |
|
| 179 | + { |
|
| 180 | + return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Format a message whenever the storage is offline. |
|
| 185 | + * |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | + protected function formatMessageForStorageOffline() |
|
| 189 | + { |
|
| 190 | + // TODO: after dropping typo3 7.6 support, remove class: typo3-message message-warning message-header message-body |
|
| 191 | + |
|
| 192 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 193 | + |
|
| 194 | + $result = <<< EOF |
|
| 195 | 195 | <div class="typo3-message message-warning alert alert-warning"> |
| 196 | 196 | <div class="message-header alert-title"> |
| 197 | 197 | Storage is currently offline |
@@ -203,78 +203,78 @@ discard block |
||
| 203 | 203 | </div> |
| 204 | 204 | EOF; |
| 205 | 205 | |
| 206 | - return $result; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Check whether mount points privilege are ok. |
|
| 211 | - * |
|
| 212 | - * @return boolean |
|
| 213 | - */ |
|
| 214 | - protected function checkMountPoints() |
|
| 215 | - { |
|
| 216 | - if (!$this->getBackendUser()->isAdmin()) { |
|
| 217 | - |
|
| 218 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 219 | - |
|
| 220 | - $fileMountIdentifiers = []; |
|
| 221 | - foreach ($fileMounts as $fileMount) { |
|
| 222 | - $fileMountIdentifiers[] = $fileMount['uid']; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 226 | - $storageRecord = $storage->getStorageRecord(); |
|
| 227 | - $fieldNames = array( |
|
| 228 | - 'mount_point_file_type_1', |
|
| 229 | - 'mount_point_file_type_2', |
|
| 230 | - 'mount_point_file_type_3', |
|
| 231 | - 'mount_point_file_type_4', |
|
| 232 | - 'mount_point_file_type_5', |
|
| 233 | - ); |
|
| 234 | - foreach ($fieldNames as $fileName) { |
|
| 235 | - $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
| 236 | - if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
| 237 | - $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
| 238 | - } else { |
|
| 239 | - # $fileMountIdentifier |
|
| 240 | - $folder = $storage->getRootLevelFolder(); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - return empty($this->notAllowedMountPoints); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * Return a mount point according to an file mount identifier. |
|
| 249 | - * |
|
| 250 | - * @param string $identifier |
|
| 251 | - * @return array |
|
| 252 | - */ |
|
| 253 | - protected function fetchMountPoint($identifier) |
|
| 254 | - { |
|
| 255 | - return $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_filemounts', 'uid = ' . $identifier); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * Format a message whenever mount points privilege are not OK. |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - protected function formatMessageForMountPoints() |
|
| 264 | - { |
|
| 265 | - |
|
| 266 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 267 | - $backendUser = $this->getBackendUser(); |
|
| 268 | - |
|
| 269 | - foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
| 270 | - $list = sprintf('<li>"%s" with path %s</li>', |
|
| 271 | - $notAllowedMountPoints['title'], |
|
| 272 | - $notAllowedMountPoints['path'] |
|
| 273 | - ); |
|
| 274 | - |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $result = <<< EOF |
|
| 206 | + return $result; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Check whether mount points privilege are ok. |
|
| 211 | + * |
|
| 212 | + * @return boolean |
|
| 213 | + */ |
|
| 214 | + protected function checkMountPoints() |
|
| 215 | + { |
|
| 216 | + if (!$this->getBackendUser()->isAdmin()) { |
|
| 217 | + |
|
| 218 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 219 | + |
|
| 220 | + $fileMountIdentifiers = []; |
|
| 221 | + foreach ($fileMounts as $fileMount) { |
|
| 222 | + $fileMountIdentifiers[] = $fileMount['uid']; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 226 | + $storageRecord = $storage->getStorageRecord(); |
|
| 227 | + $fieldNames = array( |
|
| 228 | + 'mount_point_file_type_1', |
|
| 229 | + 'mount_point_file_type_2', |
|
| 230 | + 'mount_point_file_type_3', |
|
| 231 | + 'mount_point_file_type_4', |
|
| 232 | + 'mount_point_file_type_5', |
|
| 233 | + ); |
|
| 234 | + foreach ($fieldNames as $fileName) { |
|
| 235 | + $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
| 236 | + if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
| 237 | + $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
| 238 | + } else { |
|
| 239 | + # $fileMountIdentifier |
|
| 240 | + $folder = $storage->getRootLevelFolder(); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + return empty($this->notAllowedMountPoints); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * Return a mount point according to an file mount identifier. |
|
| 249 | + * |
|
| 250 | + * @param string $identifier |
|
| 251 | + * @return array |
|
| 252 | + */ |
|
| 253 | + protected function fetchMountPoint($identifier) |
|
| 254 | + { |
|
| 255 | + return $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', 'sys_filemounts', 'uid = ' . $identifier); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * Format a message whenever mount points privilege are not OK. |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + protected function formatMessageForMountPoints() |
|
| 264 | + { |
|
| 265 | + |
|
| 266 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 267 | + $backendUser = $this->getBackendUser(); |
|
| 268 | + |
|
| 269 | + foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
| 270 | + $list = sprintf('<li>"%s" with path %s</li>', |
|
| 271 | + $notAllowedMountPoints['title'], |
|
| 272 | + $notAllowedMountPoints['path'] |
|
| 273 | + ); |
|
| 274 | + |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $result = <<< EOF |
|
| 278 | 278 | <div class="typo3-message message-warning alert alert-warning"> |
| 279 | 279 | <div class="message-header alert-title"> |
| 280 | 280 | File mount are wrongly configured for user "{$backendUser->user['username']}". |
@@ -289,40 +289,40 @@ discard block |
||
| 289 | 289 | </div> |
| 290 | 290 | EOF; |
| 291 | 291 | |
| 292 | - return $result; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @return boolean |
|
| 297 | - */ |
|
| 298 | - protected function canBeInitializedSilently() |
|
| 299 | - { |
|
| 300 | - $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS number_of_files', 'sys_file', ''); |
|
| 301 | - return (int)$record['number_of_files']; |
|
| 302 | - |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * Check whether the column "total_of_references" has been already processed once. |
|
| 307 | - * |
|
| 308 | - * @return boolean |
|
| 309 | - */ |
|
| 310 | - protected function checkColumnNumberOfReferences() |
|
| 311 | - { |
|
| 312 | - $file = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid', 'sys_file', 'number_of_references > 0'); |
|
| 313 | - return !empty($file); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * Format a message if columns "total_of_references" looks wrong. |
|
| 318 | - * |
|
| 319 | - * @param int $numberOfFile |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 322 | - protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
| 323 | - { |
|
| 324 | - |
|
| 325 | - $result = <<< EOF |
|
| 292 | + return $result; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @return boolean |
|
| 297 | + */ |
|
| 298 | + protected function canBeInitializedSilently() |
|
| 299 | + { |
|
| 300 | + $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('count(*) AS number_of_files', 'sys_file', ''); |
|
| 301 | + return (int)$record['number_of_files']; |
|
| 302 | + |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * Check whether the column "total_of_references" has been already processed once. |
|
| 307 | + * |
|
| 308 | + * @return boolean |
|
| 309 | + */ |
|
| 310 | + protected function checkColumnNumberOfReferences() |
|
| 311 | + { |
|
| 312 | + $file = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid', 'sys_file', 'number_of_references > 0'); |
|
| 313 | + return !empty($file); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * Format a message if columns "total_of_references" looks wrong. |
|
| 318 | + * |
|
| 319 | + * @param int $numberOfFile |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | + protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
| 323 | + { |
|
| 324 | + |
|
| 325 | + $result = <<< EOF |
|
| 326 | 326 | <div class="typo3-message message-ok alert alert-success"> |
| 327 | 327 | <div class="message-header alert-title"> |
| 328 | 328 | Initialized column "number_of_references" for ${numberOfFile} files |
@@ -339,19 +339,19 @@ discard block |
||
| 339 | 339 | </div> |
| 340 | 340 | EOF; |
| 341 | 341 | |
| 342 | - return $result; |
|
| 343 | - } |
|
| 342 | + return $result; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * Format a message if columns "total_of_references" looks wrong. |
|
| 348 | - * |
|
| 349 | - * @return string |
|
| 350 | - */ |
|
| 351 | - protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
| 352 | - { |
|
| 346 | + /** |
|
| 347 | + * Format a message if columns "total_of_references" looks wrong. |
|
| 348 | + * |
|
| 349 | + * @return string |
|
| 350 | + */ |
|
| 351 | + protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
| 352 | + { |
|
| 353 | 353 | |
| 354 | - $result = <<< EOF |
|
| 354 | + $result = <<< EOF |
|
| 355 | 355 | <div class="typo3-message message-warning alert alert-warning"> |
| 356 | 356 | <div class="message-header alert-title"> |
| 357 | 357 | Column "number_of_references" requires to be initialized. |
@@ -370,35 +370,35 @@ discard block |
||
| 370 | 370 | </div> |
| 371 | 371 | EOF; |
| 372 | 372 | |
| 373 | - return $result; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Returns an instance of the current Backend User. |
|
| 378 | - * |
|
| 379 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 380 | - */ |
|
| 381 | - protected function getBackendUser() |
|
| 382 | - { |
|
| 383 | - return $GLOBALS['BE_USER']; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Return a pointer to the database. |
|
| 388 | - * |
|
| 389 | - * @return \Fab\Vidi\Database\DatabaseConnection |
|
| 390 | - */ |
|
| 391 | - protected function getDatabaseConnection() |
|
| 392 | - { |
|
| 393 | - return $GLOBALS['TYPO3_DB']; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * @return MediaModule|object |
|
| 398 | - */ |
|
| 399 | - protected function getMediaModule() |
|
| 400 | - { |
|
| 401 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 402 | - } |
|
| 373 | + return $result; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Returns an instance of the current Backend User. |
|
| 378 | + * |
|
| 379 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 380 | + */ |
|
| 381 | + protected function getBackendUser() |
|
| 382 | + { |
|
| 383 | + return $GLOBALS['BE_USER']; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Return a pointer to the database. |
|
| 388 | + * |
|
| 389 | + * @return \Fab\Vidi\Database\DatabaseConnection |
|
| 390 | + */ |
|
| 391 | + protected function getDatabaseConnection() |
|
| 392 | + { |
|
| 393 | + return $GLOBALS['TYPO3_DB']; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * @return MediaModule|object |
|
| 398 | + */ |
|
| 399 | + protected function getMediaModule() |
|
| 400 | + { |
|
| 401 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 402 | + } |
|
| 403 | 403 | |
| 404 | 404 | } |
@@ -25,38 +25,38 @@ |
||
| 25 | 25 | class FilePickerMenuItem extends AbstractComponentView |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Renders a "file picker" menu item to be placed in the grid menu of Media. |
|
| 30 | - * |
|
| 31 | - * @return string |
|
| 32 | - */ |
|
| 33 | - public function render() |
|
| 34 | - { |
|
| 35 | - $result = ''; |
|
| 36 | - if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
| 37 | - $result = sprintf('<li><a href="%s" class="mass-file-picker" data-argument="assets">%s Insert files</a>', |
|
| 38 | - $this->getMassDeleteUri(), |
|
| 39 | - $this->getIconFactory()->getIcon('extensions-media-image-export', Icon::SIZE_SMALL) |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - return $result; |
|
| 43 | - } |
|
| 28 | + /** |
|
| 29 | + * Renders a "file picker" menu item to be placed in the grid menu of Media. |
|
| 30 | + * |
|
| 31 | + * @return string |
|
| 32 | + */ |
|
| 33 | + public function render() |
|
| 34 | + { |
|
| 35 | + $result = ''; |
|
| 36 | + if ($this->getModuleLoader()->hasPlugin('filePicker')) { |
|
| 37 | + $result = sprintf('<li><a href="%s" class="mass-file-picker" data-argument="assets">%s Insert files</a>', |
|
| 38 | + $this->getMassDeleteUri(), |
|
| 39 | + $this->getIconFactory()->getIcon('extensions-media-image-export', Icon::SIZE_SMALL) |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + return $result; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Render a mass delete URI. |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 50 | - protected function getMassDeleteUri() |
|
| 51 | - { |
|
| 52 | - $urlParameters = array( |
|
| 53 | - MediaModule::getParameterPrefix() => array( |
|
| 54 | - 'controller' => 'Asset', |
|
| 55 | - 'action' => '', |
|
| 56 | - 'format' => 'json', |
|
| 57 | - ), |
|
| 58 | - ); |
|
| 59 | - return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 60 | - } |
|
| 45 | + /** |
|
| 46 | + * Render a mass delete URI. |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | + protected function getMassDeleteUri() |
|
| 51 | + { |
|
| 52 | + $urlParameters = array( |
|
| 53 | + MediaModule::getParameterPrefix() => array( |
|
| 54 | + 'controller' => 'Asset', |
|
| 55 | + 'action' => '', |
|
| 56 | + 'format' => 'json', |
|
| 57 | + ), |
|
| 58 | + ); |
|
| 59 | + return BackendUtility::getModuleUrl(MediaModule::getSignature(), $urlParameters); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | } |
@@ -22,25 +22,25 @@ |
||
| 22 | 22 | class CategoryRenderer extends ColumnRendererAbstract |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Renders category list of an asset in the grid. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function render() |
|
| 31 | - { |
|
| 32 | - $result = ''; |
|
| 25 | + /** |
|
| 26 | + * Renders category list of an asset in the grid. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function render() |
|
| 31 | + { |
|
| 32 | + $result = ''; |
|
| 33 | 33 | |
| 34 | - $categories = $this->object['metadata']['categories']; |
|
| 35 | - if (!empty($categories)) { |
|
| 34 | + $categories = $this->object['metadata']['categories']; |
|
| 35 | + if (!empty($categories)) { |
|
| 36 | 36 | |
| 37 | - /** @var $category \TYPO3\CMS\Extbase\Domain\Model\Category */ |
|
| 38 | - foreach ($categories as $category) { |
|
| 39 | - $result .= sprintf('<li>%s</li>', $category['title']); |
|
| 40 | - } |
|
| 41 | - $result = sprintf('<ul class="category-list">%s</ul>', $result); |
|
| 42 | - } |
|
| 43 | - return $result; |
|
| 44 | - } |
|
| 37 | + /** @var $category \TYPO3\CMS\Extbase\Domain\Model\Category */ |
|
| 38 | + foreach ($categories as $category) { |
|
| 39 | + $result .= sprintf('<li>%s</li>', $category['title']); |
|
| 40 | + } |
|
| 41 | + $result = sprintf('<ul class="category-list">%s</ul>', $result); |
|
| 42 | + } |
|
| 43 | + return $result; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
@@ -22,24 +22,24 @@ |
||
| 22 | 22 | class FrontendPermissionRenderer extends ColumnRendererAbstract |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Render permission in the grid. |
|
| 27 | - * |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function render() |
|
| 31 | - { |
|
| 32 | - $result = ''; |
|
| 25 | + /** |
|
| 26 | + * Render permission in the grid. |
|
| 27 | + * |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function render() |
|
| 31 | + { |
|
| 32 | + $result = ''; |
|
| 33 | 33 | |
| 34 | - $frontendUserGroups = $this->object['metadata']['fe_groups']; |
|
| 35 | - if (!empty($frontendUserGroups)) { |
|
| 34 | + $frontendUserGroups = $this->object['metadata']['fe_groups']; |
|
| 35 | + if (!empty($frontendUserGroups)) { |
|
| 36 | 36 | |
| 37 | - /** @var $frontendUserGroup \TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup */ |
|
| 38 | - foreach ($frontendUserGroups as $frontendUserGroup) { |
|
| 39 | - $result .= sprintf('<li style="list-style: disc">%s</li>', $frontendUserGroup['title']); |
|
| 40 | - } |
|
| 41 | - $result = sprintf('<ul>%s</ul>', $result); |
|
| 42 | - } |
|
| 43 | - return $result; |
|
| 44 | - } |
|
| 37 | + /** @var $frontendUserGroup \TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup */ |
|
| 38 | + foreach ($frontendUserGroups as $frontendUserGroup) { |
|
| 39 | + $result .= sprintf('<li style="list-style: disc">%s</li>', $frontendUserGroup['title']); |
|
| 40 | + } |
|
| 41 | + $result = sprintf('<ul>%s</ul>', $result); |
|
| 42 | + } |
|
| 43 | + return $result; |
|
| 44 | + } |
|
| 45 | 45 | } |
@@ -20,14 +20,14 @@ |
||
| 20 | 20 | interface FormFieldInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public function render(); |
|
| 23 | + /** |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public function render(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $template |
|
| 30 | - * @return \Fab\Media\Form\FormFieldInterface |
|
| 31 | - */ |
|
| 32 | - public function setTemplate($template); |
|
| 28 | + /** |
|
| 29 | + * @param string $template |
|
| 30 | + * @return \Fab\Media\Form\FormFieldInterface |
|
| 31 | + */ |
|
| 32 | + public function setTemplate($template); |
|
| 33 | 33 | } |