@@ -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 | { |
@@ -22,247 +22,247 @@ |
||
| 22 | 22 | class CacheService |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Traverse all files and initialize cache values. |
|
| 27 | - * |
|
| 28 | - * @return int |
|
| 29 | - */ |
|
| 30 | - public function warmUp() |
|
| 31 | - { |
|
| 32 | - /** @var QueryBuilder $queryBuilder */ |
|
| 33 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 34 | - $rows = $queryBuilder |
|
| 35 | - ->select('*') |
|
| 36 | - ->from('sys_file') |
|
| 37 | - ->where('storage > 0') |
|
| 38 | - ->execute() |
|
| 39 | - ->fetchAll(); |
|
| 40 | - |
|
| 41 | - $counter = 0; |
|
| 42 | - foreach ($rows as $row) { |
|
| 43 | - |
|
| 44 | - $fileIdentifier = $row['uid']; |
|
| 45 | - $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
| 46 | - |
|
| 47 | - $values = array( |
|
| 48 | - 'number_of_references' => $totalNumberOfReferences |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - $this->getDataService()->update( |
|
| 52 | - 'sys_file', |
|
| 53 | - $values, |
|
| 54 | - [ |
|
| 55 | - 'uid' => $fileIdentifier |
|
| 56 | - ] |
|
| 57 | - ); |
|
| 58 | - $counter++; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $counter; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Clear all possible cache related to a file. |
|
| 66 | - * This method is useful when replacing a file for instance. |
|
| 67 | - * |
|
| 68 | - * @param File $file |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function clearCache(File $file) |
|
| 72 | - { |
|
| 73 | - |
|
| 74 | - $this->clearCachePages($file); |
|
| 75 | - $this->flushProcessedFiles($file); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Remove all processed files that belong to the given File object. |
|
| 80 | - * |
|
| 81 | - * @param File $file |
|
| 82 | - * @return void |
|
| 83 | - */ |
|
| 84 | - protected function flushProcessedFiles(File $file) |
|
| 85 | - { |
|
| 86 | - |
|
| 87 | - /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
| 88 | - foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
| 89 | - if ($processedFile->exists()) { |
|
| 90 | - $processedFile->delete(true); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $this->getDataService()->delete( |
|
| 94 | - 'sys_file_processedfile', |
|
| 95 | - [ |
|
| 96 | - 'uid' => (int)$processedFile->getUid() |
|
| 97 | - ] |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Return a processed file repository |
|
| 104 | - * |
|
| 105 | - * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
| 106 | - */ |
|
| 107 | - protected function getProcessedFileRepository() |
|
| 108 | - { |
|
| 109 | - return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Returns the file references. |
|
| 114 | - * |
|
| 115 | - * @param File $file |
|
| 116 | - * @return void |
|
| 117 | - */ |
|
| 118 | - protected function clearCachePages($file) |
|
| 119 | - { |
|
| 120 | - |
|
| 121 | - /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 122 | - $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
| 123 | - $tce->start([], []); |
|
| 124 | - |
|
| 125 | - #$pages = array_merge( |
|
| 126 | - # $this->findPagesWithFileReferences($file), |
|
| 127 | - # $this->findPagesWithSoftReferences($file) |
|
| 128 | - #); |
|
| 129 | - |
|
| 130 | - // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
| 131 | - // It is adviced to use "registerPageCacheClearing" but how? |
|
| 132 | - #foreach (array_unique($pages) as $page) { |
|
| 133 | - # $tce->clear_cache('pages', $page); |
|
| 134 | - #} |
|
| 135 | - $tce->clear_cacheCmd('pages'); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Find all pages which contains file references to the given $file. |
|
| 140 | - * |
|
| 141 | - * @param File $file |
|
| 142 | - * @return array |
|
| 143 | - */ |
|
| 144 | - protected function findPagesWithFileReferences($file) |
|
| 145 | - { |
|
| 146 | - |
|
| 147 | - /** @var QueryBuilder $queryBuilder */ |
|
| 148 | - $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
| 149 | - $rows = $queryBuilder |
|
| 150 | - ->select('pid') |
|
| 151 | - ->from('sys_file_reference') |
|
| 152 | - ->groupBy('pid') // no support for distinct |
|
| 153 | - ->andWhere( |
|
| 154 | - 'pid > 0', |
|
| 155 | - 'uid_local = ' . $file->getUid() |
|
| 156 | - ) |
|
| 157 | - ->execute() |
|
| 158 | - ->fetchAll(); |
|
| 159 | - |
|
| 160 | - foreach ($rows as $row) { |
|
| 161 | - $pages[] = $row['pid']; |
|
| 162 | - |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $pages; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Find all pages which have soft references to the given $file. |
|
| 170 | - * |
|
| 171 | - * @param File $file |
|
| 172 | - * @return array |
|
| 173 | - */ |
|
| 174 | - protected function findPagesWithSoftReferences(File $file) |
|
| 175 | - { |
|
| 176 | - |
|
| 177 | - // todo here... |
|
| 178 | - $subClauseParts = array( |
|
| 179 | - 'deleted = 0', |
|
| 180 | - '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 181 | - 'ref_table = "sys_file"', |
|
| 182 | - 'tablename = "tt_content"', |
|
| 183 | - 'ref_uid = ' . $file->getUid(), |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 187 | - 'DISTINCT pid', |
|
| 188 | - 'tt_content', |
|
| 189 | - sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 190 | - implode(' AND ', $subClauseParts), |
|
| 191 | - $this->getWhereClauseForEnabledFields('tt_content') |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - // Compute result |
|
| 196 | - $pages = []; |
|
| 197 | - while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 198 | - $pages[] = $affectedPage['pid']; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $pages; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 206 | - * |
|
| 207 | - * @param string $tableName |
|
| 208 | - * @return string |
|
| 209 | - */ |
|
| 210 | - protected function getWhereClauseForEnabledFields($tableName) |
|
| 211 | - { |
|
| 212 | - if ($this->isFrontendMode()) { |
|
| 213 | - // frontend context |
|
| 214 | - $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 215 | - } else { |
|
| 216 | - // backend context |
|
| 217 | - $whereClause = BackendUtility::deleteClause($tableName); |
|
| 218 | - } |
|
| 219 | - return $whereClause; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Returns whether the current mode is Frontend |
|
| 224 | - * |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - protected function isFrontendMode() |
|
| 228 | - { |
|
| 229 | - return TYPO3_MODE == 'FE'; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Returns an instance of the page repository. |
|
| 234 | - * |
|
| 235 | - * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 236 | - */ |
|
| 237 | - protected function getPageRepository() |
|
| 238 | - { |
|
| 239 | - return $GLOBALS['TSFE']->sys_page; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * @param string $tableName |
|
| 244 | - * @return object|QueryBuilder |
|
| 245 | - */ |
|
| 246 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
| 247 | - { |
|
| 248 | - /** @var ConnectionPool $connectionPool */ |
|
| 249 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 250 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * @return object|DataService |
|
| 255 | - */ |
|
| 256 | - protected function getDataService(): DataService |
|
| 257 | - { |
|
| 258 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 263 | - */ |
|
| 264 | - protected function getFileReferenceService() |
|
| 265 | - { |
|
| 266 | - return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 267 | - } |
|
| 25 | + /** |
|
| 26 | + * Traverse all files and initialize cache values. |
|
| 27 | + * |
|
| 28 | + * @return int |
|
| 29 | + */ |
|
| 30 | + public function warmUp() |
|
| 31 | + { |
|
| 32 | + /** @var QueryBuilder $queryBuilder */ |
|
| 33 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 34 | + $rows = $queryBuilder |
|
| 35 | + ->select('*') |
|
| 36 | + ->from('sys_file') |
|
| 37 | + ->where('storage > 0') |
|
| 38 | + ->execute() |
|
| 39 | + ->fetchAll(); |
|
| 40 | + |
|
| 41 | + $counter = 0; |
|
| 42 | + foreach ($rows as $row) { |
|
| 43 | + |
|
| 44 | + $fileIdentifier = $row['uid']; |
|
| 45 | + $totalNumberOfReferences = $this->getFileReferenceService()->countTotalReferences($fileIdentifier); |
|
| 46 | + |
|
| 47 | + $values = array( |
|
| 48 | + 'number_of_references' => $totalNumberOfReferences |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + $this->getDataService()->update( |
|
| 52 | + 'sys_file', |
|
| 53 | + $values, |
|
| 54 | + [ |
|
| 55 | + 'uid' => $fileIdentifier |
|
| 56 | + ] |
|
| 57 | + ); |
|
| 58 | + $counter++; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $counter; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Clear all possible cache related to a file. |
|
| 66 | + * This method is useful when replacing a file for instance. |
|
| 67 | + * |
|
| 68 | + * @param File $file |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function clearCache(File $file) |
|
| 72 | + { |
|
| 73 | + |
|
| 74 | + $this->clearCachePages($file); |
|
| 75 | + $this->flushProcessedFiles($file); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Remove all processed files that belong to the given File object. |
|
| 80 | + * |
|
| 81 | + * @param File $file |
|
| 82 | + * @return void |
|
| 83 | + */ |
|
| 84 | + protected function flushProcessedFiles(File $file) |
|
| 85 | + { |
|
| 86 | + |
|
| 87 | + /** @var $processedFile \TYPO3\CMS\Core\Resource\ProcessedFile */ |
|
| 88 | + foreach ($this->getProcessedFileRepository()->findAllByOriginalFile($file) as $processedFile) { |
|
| 89 | + if ($processedFile->exists()) { |
|
| 90 | + $processedFile->delete(true); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $this->getDataService()->delete( |
|
| 94 | + 'sys_file_processedfile', |
|
| 95 | + [ |
|
| 96 | + 'uid' => (int)$processedFile->getUid() |
|
| 97 | + ] |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Return a processed file repository |
|
| 104 | + * |
|
| 105 | + * @return \TYPO3\CMS\Core\Resource\ProcessedFileRepository|object |
|
| 106 | + */ |
|
| 107 | + protected function getProcessedFileRepository() |
|
| 108 | + { |
|
| 109 | + return GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ProcessedFileRepository::class); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Returns the file references. |
|
| 114 | + * |
|
| 115 | + * @param File $file |
|
| 116 | + * @return void |
|
| 117 | + */ |
|
| 118 | + protected function clearCachePages($file) |
|
| 119 | + { |
|
| 120 | + |
|
| 121 | + /** @var $tce \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 122 | + $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class); |
|
| 123 | + $tce->start([], []); |
|
| 124 | + |
|
| 125 | + #$pages = array_merge( |
|
| 126 | + # $this->findPagesWithFileReferences($file), |
|
| 127 | + # $this->findPagesWithSoftReferences($file) |
|
| 128 | + #); |
|
| 129 | + |
|
| 130 | + // Previous code which does not work in TYPO3 CMS 7 LTS. |
|
| 131 | + // It is adviced to use "registerPageCacheClearing" but how? |
|
| 132 | + #foreach (array_unique($pages) as $page) { |
|
| 133 | + # $tce->clear_cache('pages', $page); |
|
| 134 | + #} |
|
| 135 | + $tce->clear_cacheCmd('pages'); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Find all pages which contains file references to the given $file. |
|
| 140 | + * |
|
| 141 | + * @param File $file |
|
| 142 | + * @return array |
|
| 143 | + */ |
|
| 144 | + protected function findPagesWithFileReferences($file) |
|
| 145 | + { |
|
| 146 | + |
|
| 147 | + /** @var QueryBuilder $queryBuilder */ |
|
| 148 | + $queryBuilder = $this->getQueryBuilder('sys_file_reference'); |
|
| 149 | + $rows = $queryBuilder |
|
| 150 | + ->select('pid') |
|
| 151 | + ->from('sys_file_reference') |
|
| 152 | + ->groupBy('pid') // no support for distinct |
|
| 153 | + ->andWhere( |
|
| 154 | + 'pid > 0', |
|
| 155 | + 'uid_local = ' . $file->getUid() |
|
| 156 | + ) |
|
| 157 | + ->execute() |
|
| 158 | + ->fetchAll(); |
|
| 159 | + |
|
| 160 | + foreach ($rows as $row) { |
|
| 161 | + $pages[] = $row['pid']; |
|
| 162 | + |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return $pages; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Find all pages which have soft references to the given $file. |
|
| 170 | + * |
|
| 171 | + * @param File $file |
|
| 172 | + * @return array |
|
| 173 | + */ |
|
| 174 | + protected function findPagesWithSoftReferences(File $file) |
|
| 175 | + { |
|
| 176 | + |
|
| 177 | + // todo here... |
|
| 178 | + $subClauseParts = array( |
|
| 179 | + 'deleted = 0', |
|
| 180 | + '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
|
| 181 | + 'ref_table = "sys_file"', |
|
| 182 | + 'tablename = "tt_content"', |
|
| 183 | + 'ref_uid = ' . $file->getUid(), |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
|
| 187 | + 'DISTINCT pid', |
|
| 188 | + 'tt_content', |
|
| 189 | + sprintf('uid IN (SELECT recuid FROM sys_refindex WHERE %s) %s', |
|
| 190 | + implode(' AND ', $subClauseParts), |
|
| 191 | + $this->getWhereClauseForEnabledFields('tt_content') |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + // Compute result |
|
| 196 | + $pages = []; |
|
| 197 | + while ($affectedPage = $this->getDatabaseConnection()->sql_fetch_assoc($rows)) { |
|
| 198 | + $pages[] = $affectedPage['pid']; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $pages; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Get the WHERE clause for the enabled fields given a $tableName. |
|
| 206 | + * |
|
| 207 | + * @param string $tableName |
|
| 208 | + * @return string |
|
| 209 | + */ |
|
| 210 | + protected function getWhereClauseForEnabledFields($tableName) |
|
| 211 | + { |
|
| 212 | + if ($this->isFrontendMode()) { |
|
| 213 | + // frontend context |
|
| 214 | + $whereClause = $this->getPageRepository()->deleteClause($tableName); |
|
| 215 | + } else { |
|
| 216 | + // backend context |
|
| 217 | + $whereClause = BackendUtility::deleteClause($tableName); |
|
| 218 | + } |
|
| 219 | + return $whereClause; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Returns whether the current mode is Frontend |
|
| 224 | + * |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + protected function isFrontendMode() |
|
| 228 | + { |
|
| 229 | + return TYPO3_MODE == 'FE'; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Returns an instance of the page repository. |
|
| 234 | + * |
|
| 235 | + * @return \TYPO3\CMS\Frontend\Page\PageRepository |
|
| 236 | + */ |
|
| 237 | + protected function getPageRepository() |
|
| 238 | + { |
|
| 239 | + return $GLOBALS['TSFE']->sys_page; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * @param string $tableName |
|
| 244 | + * @return object|QueryBuilder |
|
| 245 | + */ |
|
| 246 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
| 247 | + { |
|
| 248 | + /** @var ConnectionPool $connectionPool */ |
|
| 249 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 250 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * @return object|DataService |
|
| 255 | + */ |
|
| 256 | + protected function getDataService(): DataService |
|
| 257 | + { |
|
| 258 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @return \Fab\Media\Resource\FileReferenceService|object |
|
| 263 | + */ |
|
| 264 | + protected function getFileReferenceService() |
|
| 265 | + { |
|
| 266 | + return GeneralUtility::makeInstance(\Fab\Media\Resource\FileReferenceService::class); |
|
| 267 | + } |
|
| 268 | 268 | } |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | ->groupBy('pid') // no support for distinct |
| 153 | 153 | ->andWhere( |
| 154 | 154 | 'pid > 0', |
| 155 | - 'uid_local = ' . $file->getUid() |
|
| 155 | + 'uid_local = '.$file->getUid() |
|
| 156 | 156 | ) |
| 157 | 157 | ->execute() |
| 158 | 158 | ->fetchAll(); |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | '(softref_key = "rtehtmlarea_images" OR softref_key = "typolink_tag")', |
| 181 | 181 | 'ref_table = "sys_file"', |
| 182 | 182 | 'tablename = "tt_content"', |
| 183 | - 'ref_uid = ' . $file->getUid(), |
|
| 183 | + 'ref_uid = '.$file->getUid(), |
|
| 184 | 184 | ); |
| 185 | 185 | |
| 186 | 186 | $rows = $this->getDatabaseConnection()->exec_SELECTquery( |
@@ -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 | { |
@@ -21,139 +21,139 @@ discard block |
||
| 21 | 21 | class ConfigurationWarning extends AbstractComponentView |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected $notAllowedMountPoints = []; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Renders a button for uploading assets. |
|
| 31 | - * |
|
| 32 | - * @return string |
|
| 33 | - */ |
|
| 34 | - public function render() |
|
| 35 | - { |
|
| 36 | - |
|
| 37 | - $result = ''; |
|
| 38 | - |
|
| 39 | - // Check whether storage is configured or not. |
|
| 40 | - if ($this->checkStorageNotConfigured()) { |
|
| 41 | - $this->configureStorage(); |
|
| 42 | - $result .= $this->formatMessageForStorageConfigured(); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // Check whether storage is online or not. |
|
| 46 | - if ($this->checkStorageOffline()) { |
|
| 47 | - $result .= $this->formatMessageForStorageOffline(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // Check all mount points of the storage are available |
|
| 51 | - if (!$this->checkMountPoints()) { |
|
| 52 | - $result .= $this->formatMessageForMountPoints(); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // Check all mount points of the storage are available |
|
| 56 | - if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
| 57 | - if ($this->canBeInitializedSilently() < 2000) { |
|
| 58 | - $numberOfFiles = $this->getCacheService()->warmUp(); |
|
| 59 | - $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
| 60 | - touch($this->getWarmUpSemaphoreFile()); |
|
| 61 | - } else { |
|
| 62 | - $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - return $result; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return \Fab\Media\Cache\CacheService|object |
|
| 71 | - */ |
|
| 72 | - protected function getCacheService() |
|
| 73 | - { |
|
| 74 | - return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return boolean |
|
| 79 | - */ |
|
| 80 | - protected function configureStorage() |
|
| 81 | - { |
|
| 82 | - $tableName = 'sys_file_storage'; |
|
| 83 | - $fields = array( |
|
| 84 | - 'maximum_dimension_original_image', |
|
| 85 | - 'extension_allowed_file_type_1', |
|
| 86 | - 'extension_allowed_file_type_2', |
|
| 87 | - 'extension_allowed_file_type_3', |
|
| 88 | - 'extension_allowed_file_type_4', |
|
| 89 | - 'extension_allowed_file_type_5', |
|
| 90 | - ); |
|
| 91 | - |
|
| 92 | - $values = []; |
|
| 93 | - foreach ($fields as $field) { |
|
| 94 | - $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 98 | - $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return bool |
|
| 103 | - */ |
|
| 104 | - protected function hasBeenWarmedUp() |
|
| 105 | - { |
|
| 106 | - return is_file(($this->getWarmUpSemaphoreFile())); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - protected function getWarmUpSemaphoreFile() |
|
| 113 | - { |
|
| 114 | - return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Check whether the storage is correctly configured. |
|
| 119 | - * |
|
| 120 | - * @return boolean |
|
| 121 | - */ |
|
| 122 | - protected function checkStorageNotConfigured() |
|
| 123 | - { |
|
| 124 | - $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 125 | - $storageRecord = $currentStorage->getStorageRecord(); |
|
| 126 | - |
|
| 127 | - // Take the storage fields and check whether some data was initialized. |
|
| 128 | - $fields = array( |
|
| 129 | - 'extension_allowed_file_type_1', |
|
| 130 | - 'extension_allowed_file_type_2', |
|
| 131 | - 'extension_allowed_file_type_3', |
|
| 132 | - 'extension_allowed_file_type_4', |
|
| 133 | - 'extension_allowed_file_type_5', |
|
| 134 | - ); |
|
| 135 | - |
|
| 136 | - $result = true; |
|
| 137 | - foreach ($fields as $fieldName) { |
|
| 138 | - // true means the storage has data and thus was configured / saved once. |
|
| 139 | - if (!empty($storageRecord[$fieldName])) { |
|
| 140 | - $result = false; |
|
| 141 | - break; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - return $result; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * Format a message whenever the storage is offline. |
|
| 149 | - * |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 152 | - protected function formatMessageForStorageConfigured() |
|
| 153 | - { |
|
| 154 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 155 | - |
|
| 156 | - $result = <<< EOF |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected $notAllowedMountPoints = []; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Renders a button for uploading assets. |
|
| 31 | + * |
|
| 32 | + * @return string |
|
| 33 | + */ |
|
| 34 | + public function render() |
|
| 35 | + { |
|
| 36 | + |
|
| 37 | + $result = ''; |
|
| 38 | + |
|
| 39 | + // Check whether storage is configured or not. |
|
| 40 | + if ($this->checkStorageNotConfigured()) { |
|
| 41 | + $this->configureStorage(); |
|
| 42 | + $result .= $this->formatMessageForStorageConfigured(); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // Check whether storage is online or not. |
|
| 46 | + if ($this->checkStorageOffline()) { |
|
| 47 | + $result .= $this->formatMessageForStorageOffline(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // Check all mount points of the storage are available |
|
| 51 | + if (!$this->checkMountPoints()) { |
|
| 52 | + $result .= $this->formatMessageForMountPoints(); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // Check all mount points of the storage are available |
|
| 56 | + if (!$this->hasBeenWarmedUp() && !$this->checkColumnNumberOfReferences()) { |
|
| 57 | + if ($this->canBeInitializedSilently() < 2000) { |
|
| 58 | + $numberOfFiles = $this->getCacheService()->warmUp(); |
|
| 59 | + $result .= $this->formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFiles); |
|
| 60 | + touch($this->getWarmUpSemaphoreFile()); |
|
| 61 | + } else { |
|
| 62 | + $result .= $this->formatMessageForUpdateRequiredColumnNumberOfReferences(); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + return $result; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return \Fab\Media\Cache\CacheService|object |
|
| 71 | + */ |
|
| 72 | + protected function getCacheService() |
|
| 73 | + { |
|
| 74 | + return GeneralUtility::makeInstance(\Fab\Media\Cache\CacheService::class); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return boolean |
|
| 79 | + */ |
|
| 80 | + protected function configureStorage() |
|
| 81 | + { |
|
| 82 | + $tableName = 'sys_file_storage'; |
|
| 83 | + $fields = array( |
|
| 84 | + 'maximum_dimension_original_image', |
|
| 85 | + 'extension_allowed_file_type_1', |
|
| 86 | + 'extension_allowed_file_type_2', |
|
| 87 | + 'extension_allowed_file_type_3', |
|
| 88 | + 'extension_allowed_file_type_4', |
|
| 89 | + 'extension_allowed_file_type_5', |
|
| 90 | + ); |
|
| 91 | + |
|
| 92 | + $values = []; |
|
| 93 | + foreach ($fields as $field) { |
|
| 94 | + $values[$field] = Tca::table($tableName)->field($field)->getDefaultValue(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 98 | + $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return bool |
|
| 103 | + */ |
|
| 104 | + protected function hasBeenWarmedUp() |
|
| 105 | + { |
|
| 106 | + return is_file(($this->getWarmUpSemaphoreFile())); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + protected function getWarmUpSemaphoreFile() |
|
| 113 | + { |
|
| 114 | + return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Check whether the storage is correctly configured. |
|
| 119 | + * |
|
| 120 | + * @return boolean |
|
| 121 | + */ |
|
| 122 | + protected function checkStorageNotConfigured() |
|
| 123 | + { |
|
| 124 | + $currentStorage = $this->getMediaModule()->getCurrentStorage(); |
|
| 125 | + $storageRecord = $currentStorage->getStorageRecord(); |
|
| 126 | + |
|
| 127 | + // Take the storage fields and check whether some data was initialized. |
|
| 128 | + $fields = array( |
|
| 129 | + 'extension_allowed_file_type_1', |
|
| 130 | + 'extension_allowed_file_type_2', |
|
| 131 | + 'extension_allowed_file_type_3', |
|
| 132 | + 'extension_allowed_file_type_4', |
|
| 133 | + 'extension_allowed_file_type_5', |
|
| 134 | + ); |
|
| 135 | + |
|
| 136 | + $result = true; |
|
| 137 | + foreach ($fields as $fieldName) { |
|
| 138 | + // true means the storage has data and thus was configured / saved once. |
|
| 139 | + if (!empty($storageRecord[$fieldName])) { |
|
| 140 | + $result = false; |
|
| 141 | + break; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + return $result; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * Format a message whenever the storage is offline. |
|
| 149 | + * |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | + protected function formatMessageForStorageConfigured() |
|
| 153 | + { |
|
| 154 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 155 | + |
|
| 156 | + $result = <<< EOF |
|
| 157 | 157 | <div class="alert alert-info"> |
| 158 | 158 | <div class="alert-title"> |
| 159 | 159 | Storage has been configured. |
@@ -166,29 +166,29 @@ discard block |
||
| 166 | 166 | </div> |
| 167 | 167 | EOF; |
| 168 | 168 | |
| 169 | - return $result; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * Check whether the storage is online or not. |
|
| 174 | - * |
|
| 175 | - * @return boolean |
|
| 176 | - */ |
|
| 177 | - protected function checkStorageOffline() |
|
| 178 | - { |
|
| 179 | - return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Format a message whenever the storage is offline. |
|
| 184 | - * |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - protected function formatMessageForStorageOffline() |
|
| 188 | - { |
|
| 189 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 190 | - |
|
| 191 | - $result = <<< EOF |
|
| 169 | + return $result; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * Check whether the storage is online or not. |
|
| 174 | + * |
|
| 175 | + * @return boolean |
|
| 176 | + */ |
|
| 177 | + protected function checkStorageOffline() |
|
| 178 | + { |
|
| 179 | + return !$this->getMediaModule()->getCurrentStorage()->isOnline(); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Format a message whenever the storage is offline. |
|
| 184 | + * |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + protected function formatMessageForStorageOffline() |
|
| 188 | + { |
|
| 189 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 190 | + |
|
| 191 | + $result = <<< EOF |
|
| 192 | 192 | <div class="alert alert-warning"> |
| 193 | 193 | <div class="alert-title"> |
| 194 | 194 | Storage is currently offline |
@@ -200,85 +200,85 @@ discard block |
||
| 200 | 200 | </div> |
| 201 | 201 | EOF; |
| 202 | 202 | |
| 203 | - return $result; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Check whether mount points privilege are ok. |
|
| 208 | - * |
|
| 209 | - * @return boolean |
|
| 210 | - */ |
|
| 211 | - protected function checkMountPoints() |
|
| 212 | - { |
|
| 213 | - if (!$this->getBackendUser()->isAdmin()) { |
|
| 214 | - |
|
| 215 | - $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 216 | - |
|
| 217 | - $fileMountIdentifiers = []; |
|
| 218 | - foreach ($fileMounts as $fileMount) { |
|
| 219 | - $fileMountIdentifiers[] = $fileMount['uid']; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 223 | - $storageRecord = $storage->getStorageRecord(); |
|
| 224 | - $fieldNames = array( |
|
| 225 | - 'mount_point_file_type_1', |
|
| 226 | - 'mount_point_file_type_2', |
|
| 227 | - 'mount_point_file_type_3', |
|
| 228 | - 'mount_point_file_type_4', |
|
| 229 | - 'mount_point_file_type_5', |
|
| 230 | - ); |
|
| 231 | - foreach ($fieldNames as $fileName) { |
|
| 232 | - $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
| 233 | - if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
| 234 | - $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
| 235 | - } else { |
|
| 236 | - # $fileMountIdentifier |
|
| 237 | - $folder = $storage->getRootLevelFolder(); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - return empty($this->notAllowedMountPoints); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * Return a mount point according to an file mount identifier. |
|
| 246 | - * |
|
| 247 | - * @param string $identifier |
|
| 248 | - * @return array |
|
| 249 | - */ |
|
| 250 | - protected function fetchMountPoint($identifier) |
|
| 251 | - { |
|
| 252 | - /** @var QueryBuilder $queryBuilder */ |
|
| 253 | - $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
| 254 | - return $queryBuilder |
|
| 255 | - ->select('*') |
|
| 256 | - ->from('sys_filemounts') |
|
| 257 | - ->where('uid = ' . $identifier) |
|
| 258 | - ->execute() |
|
| 259 | - ->fetch(); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Format a message whenever mount points privilege are not OK. |
|
| 264 | - * |
|
| 265 | - * @return string |
|
| 266 | - */ |
|
| 267 | - protected function formatMessageForMountPoints() |
|
| 268 | - { |
|
| 269 | - |
|
| 270 | - $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 271 | - $backendUser = $this->getBackendUser(); |
|
| 272 | - |
|
| 273 | - foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
| 274 | - $list = sprintf('<li>"%s" with path %s</li>', |
|
| 275 | - $notAllowedMountPoints['title'], |
|
| 276 | - $notAllowedMountPoints['path'] |
|
| 277 | - ); |
|
| 278 | - |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - $result = <<< EOF |
|
| 203 | + return $result; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Check whether mount points privilege are ok. |
|
| 208 | + * |
|
| 209 | + * @return boolean |
|
| 210 | + */ |
|
| 211 | + protected function checkMountPoints() |
|
| 212 | + { |
|
| 213 | + if (!$this->getBackendUser()->isAdmin()) { |
|
| 214 | + |
|
| 215 | + $fileMounts = $this->getBackendUser()->getFileMountRecords(); |
|
| 216 | + |
|
| 217 | + $fileMountIdentifiers = []; |
|
| 218 | + foreach ($fileMounts as $fileMount) { |
|
| 219 | + $fileMountIdentifiers[] = $fileMount['uid']; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 223 | + $storageRecord = $storage->getStorageRecord(); |
|
| 224 | + $fieldNames = array( |
|
| 225 | + 'mount_point_file_type_1', |
|
| 226 | + 'mount_point_file_type_2', |
|
| 227 | + 'mount_point_file_type_3', |
|
| 228 | + 'mount_point_file_type_4', |
|
| 229 | + 'mount_point_file_type_5', |
|
| 230 | + ); |
|
| 231 | + foreach ($fieldNames as $fileName) { |
|
| 232 | + $fileMountIdentifier = (int)$storageRecord[$fileName]; |
|
| 233 | + if ($fileMountIdentifier > 0 && !in_array($fileMountIdentifier, $fileMountIdentifiers)) { |
|
| 234 | + $this->notAllowedMountPoints[] = $this->fetchMountPoint($fileMountIdentifier); |
|
| 235 | + } else { |
|
| 236 | + # $fileMountIdentifier |
|
| 237 | + $folder = $storage->getRootLevelFolder(); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + return empty($this->notAllowedMountPoints); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * Return a mount point according to an file mount identifier. |
|
| 246 | + * |
|
| 247 | + * @param string $identifier |
|
| 248 | + * @return array |
|
| 249 | + */ |
|
| 250 | + protected function fetchMountPoint($identifier) |
|
| 251 | + { |
|
| 252 | + /** @var QueryBuilder $queryBuilder */ |
|
| 253 | + $queryBuilder = $this->getQueryBuilder('sys_filemounts'); |
|
| 254 | + return $queryBuilder |
|
| 255 | + ->select('*') |
|
| 256 | + ->from('sys_filemounts') |
|
| 257 | + ->where('uid = ' . $identifier) |
|
| 258 | + ->execute() |
|
| 259 | + ->fetch(); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Format a message whenever mount points privilege are not OK. |
|
| 264 | + * |
|
| 265 | + * @return string |
|
| 266 | + */ |
|
| 267 | + protected function formatMessageForMountPoints() |
|
| 268 | + { |
|
| 269 | + |
|
| 270 | + $storage = $this->getMediaModule()->getCurrentStorage(); |
|
| 271 | + $backendUser = $this->getBackendUser(); |
|
| 272 | + |
|
| 273 | + foreach ($this->notAllowedMountPoints as $notAllowedMountPoints) { |
|
| 274 | + $list = sprintf('<li>"%s" with path %s</li>', |
|
| 275 | + $notAllowedMountPoints['title'], |
|
| 276 | + $notAllowedMountPoints['path'] |
|
| 277 | + ); |
|
| 278 | + |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + $result = <<< EOF |
|
| 282 | 282 | <div class="alert alert-warning"> |
| 283 | 283 | <div class="alert-title"> |
| 284 | 284 | File mount are wrongly configured for user "{$backendUser->user['username']}". |
@@ -293,54 +293,54 @@ discard block |
||
| 293 | 293 | </div> |
| 294 | 294 | EOF; |
| 295 | 295 | |
| 296 | - return $result; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * @return boolean |
|
| 301 | - */ |
|
| 302 | - protected function canBeInitializedSilently() |
|
| 303 | - { |
|
| 304 | - /** @var QueryBuilder $queryBuilder */ |
|
| 305 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 306 | - $count = $queryBuilder |
|
| 307 | - ->count('*') |
|
| 308 | - ->from('sys_file') |
|
| 309 | - ->execute() |
|
| 310 | - ->fetchColumn(0); |
|
| 311 | - return (int)$count; |
|
| 312 | - |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Check whether the column "total_of_references" has been already processed once. |
|
| 317 | - * |
|
| 318 | - * @return boolean |
|
| 319 | - */ |
|
| 320 | - protected function checkColumnNumberOfReferences() |
|
| 321 | - { |
|
| 322 | - /** @var QueryBuilder $queryBuilder */ |
|
| 323 | - $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 324 | - $file = $queryBuilder |
|
| 325 | - ->select('*') |
|
| 326 | - ->from('sys_file') |
|
| 327 | - ->where('number_of_references > 0') |
|
| 328 | - ->execute() |
|
| 329 | - ->fetch(); |
|
| 330 | - |
|
| 331 | - return !empty($file); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * Format a message if columns "total_of_references" looks wrong. |
|
| 336 | - * |
|
| 337 | - * @param int $numberOfFile |
|
| 338 | - * @return string |
|
| 339 | - */ |
|
| 340 | - protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
| 341 | - { |
|
| 342 | - |
|
| 343 | - $result = <<< EOF |
|
| 296 | + return $result; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * @return boolean |
|
| 301 | + */ |
|
| 302 | + protected function canBeInitializedSilently() |
|
| 303 | + { |
|
| 304 | + /** @var QueryBuilder $queryBuilder */ |
|
| 305 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 306 | + $count = $queryBuilder |
|
| 307 | + ->count('*') |
|
| 308 | + ->from('sys_file') |
|
| 309 | + ->execute() |
|
| 310 | + ->fetchColumn(0); |
|
| 311 | + return (int)$count; |
|
| 312 | + |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Check whether the column "total_of_references" has been already processed once. |
|
| 317 | + * |
|
| 318 | + * @return boolean |
|
| 319 | + */ |
|
| 320 | + protected function checkColumnNumberOfReferences() |
|
| 321 | + { |
|
| 322 | + /** @var QueryBuilder $queryBuilder */ |
|
| 323 | + $queryBuilder = $this->getQueryBuilder('sys_file'); |
|
| 324 | + $file = $queryBuilder |
|
| 325 | + ->select('*') |
|
| 326 | + ->from('sys_file') |
|
| 327 | + ->where('number_of_references > 0') |
|
| 328 | + ->execute() |
|
| 329 | + ->fetch(); |
|
| 330 | + |
|
| 331 | + return !empty($file); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * Format a message if columns "total_of_references" looks wrong. |
|
| 336 | + * |
|
| 337 | + * @param int $numberOfFile |
|
| 338 | + * @return string |
|
| 339 | + */ |
|
| 340 | + protected function formatMessageForSilentlyUpdatedColumnNumberOfReferences($numberOfFile) |
|
| 341 | + { |
|
| 342 | + |
|
| 343 | + $result = <<< EOF |
|
| 344 | 344 | <div class="alert alert-success"> |
| 345 | 345 | <div class="alert-title"> |
| 346 | 346 | Initialized column "number_of_references" for ${numberOfFile} files |
@@ -357,19 +357,19 @@ discard block |
||
| 357 | 357 | </div> |
| 358 | 358 | EOF; |
| 359 | 359 | |
| 360 | - return $result; |
|
| 361 | - } |
|
| 360 | + return $result; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * Format a message if columns "total_of_references" looks wrong. |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - */ |
|
| 369 | - protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
| 370 | - { |
|
| 364 | + /** |
|
| 365 | + * Format a message if columns "total_of_references" looks wrong. |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + */ |
|
| 369 | + protected function formatMessageForUpdateRequiredColumnNumberOfReferences() |
|
| 370 | + { |
|
| 371 | 371 | |
| 372 | - $result = <<< EOF |
|
| 372 | + $result = <<< EOF |
|
| 373 | 373 | <div class="alert alert-warning"> |
| 374 | 374 | <div class="alert-title"> |
| 375 | 375 | Column "number_of_references" requires to be initialized. |
@@ -388,36 +388,36 @@ discard block |
||
| 388 | 388 | </div> |
| 389 | 389 | EOF; |
| 390 | 390 | |
| 391 | - return $result; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Returns an instance of the current Backend User. |
|
| 396 | - * |
|
| 397 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 398 | - */ |
|
| 399 | - protected function getBackendUser() |
|
| 400 | - { |
|
| 401 | - return $GLOBALS['BE_USER']; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * @param string $tableName |
|
| 406 | - * @return object|QueryBuilder |
|
| 407 | - */ |
|
| 408 | - protected function getQueryBuilder($tableName): QueryBuilder |
|
| 409 | - { |
|
| 410 | - /** @var ConnectionPool $connectionPool */ |
|
| 411 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 412 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * @return MediaModule|object |
|
| 417 | - */ |
|
| 418 | - protected function getMediaModule() |
|
| 419 | - { |
|
| 420 | - return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 421 | - } |
|
| 391 | + return $result; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Returns an instance of the current Backend User. |
|
| 396 | + * |
|
| 397 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 398 | + */ |
|
| 399 | + protected function getBackendUser() |
|
| 400 | + { |
|
| 401 | + return $GLOBALS['BE_USER']; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * @param string $tableName |
|
| 406 | + * @return object|QueryBuilder |
|
| 407 | + */ |
|
| 408 | + protected function getQueryBuilder($tableName): QueryBuilder |
|
| 409 | + { |
|
| 410 | + /** @var ConnectionPool $connectionPool */ |
|
| 411 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
| 412 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * @return MediaModule|object |
|
| 417 | + */ |
|
| 418 | + protected function getMediaModule() |
|
| 419 | + { |
|
| 420 | + return GeneralUtility::makeInstance(\Fab\Media\Module\MediaModule::class); |
|
| 421 | + } |
|
| 422 | 422 | |
| 423 | 423 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | $storage = $this->getMediaModule()->getCurrentStorage(); |
| 98 | - $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = ' . $storage->getUid(), $values); |
|
| 98 | + $this->getDatabaseConnection()->exec_UPDATEquery($tableName, 'uid = '.$storage->getUid(), $values); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | protected function getWarmUpSemaphoreFile() |
| 113 | 113 | { |
| 114 | - return PATH_site . 'typo3temp/.media_cache_warmed_up'; |
|
| 114 | + return PATH_site.'typo3temp/.media_cache_warmed_up'; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | return $queryBuilder |
| 255 | 255 | ->select('*') |
| 256 | 256 | ->from('sys_filemounts') |
| 257 | - ->where('uid = ' . $identifier) |
|
| 257 | + ->where('uid = '.$identifier) |
|
| 258 | 258 | ->execute() |
| 259 | 259 | ->fetch(); |
| 260 | 260 | } |
@@ -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 | } |