1 | <?php |
||
32 | class ConfigService extends FilesService { |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $configName = 'gallery.cnf'; |
||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $privacyChecker = '.nomedia'; |
||
42 | /** |
||
43 | * @var array <string,bool> |
||
44 | */ |
||
45 | private $completionStatus = ['design' => false, 'information' => false, 'sorting' => false]; |
||
46 | /** |
||
47 | * @var ConfigParser |
||
48 | */ |
||
49 | private $configParser; |
||
50 | /** @var Preview */ |
||
51 | private $previewManager; |
||
52 | /** |
||
53 | * @todo This hard-coded array could be replaced by admin settings |
||
54 | * |
||
55 | * @var string[] |
||
56 | */ |
||
57 | private $baseMimeTypes = [ |
||
58 | 'image/png', |
||
59 | 'image/jpeg', |
||
60 | 'image/gif', |
||
61 | 'image/x-xbitmap', |
||
62 | 'image/bmp', |
||
63 | 'image/tiff', |
||
64 | 'image/x-dcraw', |
||
65 | 'application/x-photoshop', |
||
66 | 'application/illustrator', |
||
67 | 'application/postscript', |
||
68 | ]; |
||
69 | /** |
||
70 | * These types are useful for files preview in the files app, but |
||
71 | * not for the gallery side |
||
72 | * |
||
73 | * @var string[] |
||
74 | */ |
||
75 | private $slideshowMimeTypes = [ |
||
76 | 'application/font-sfnt', |
||
77 | 'application/x-font', |
||
78 | ]; |
||
79 | |||
80 | /** |
||
81 | * Constructor |
||
82 | * |
||
83 | * @param string $appName |
||
84 | * @param Environment $environment |
||
85 | * @param ConfigParser $configParser |
||
86 | * @param Preview $previewManager |
||
87 | * @param ILogger $logger |
||
88 | */ |
||
89 | 57 | public function __construct( |
|
90 | $appName, |
||
91 | Environment $environment, |
||
92 | ConfigParser $configParser, |
||
93 | Preview $previewManager, |
||
94 | ILogger $logger |
||
95 | ) { |
||
96 | 57 | parent::__construct($appName, $environment, $logger); |
|
97 | |||
98 | 57 | $this->configParser = $configParser; |
|
99 | 57 | $this->previewManager = $previewManager; |
|
100 | 57 | } |
|
101 | |||
102 | /** |
||
103 | * Returns a list of supported features |
||
104 | * |
||
105 | * @return string[] |
||
106 | */ |
||
107 | 6 | public function getFeaturesList() { |
|
122 | |||
123 | /** |
||
124 | * This builds and returns a list of all supported media types |
||
125 | * |
||
126 | * @todo Native SVG could be disabled via admin settings |
||
127 | * |
||
128 | * @param bool $extraMediaTypes |
||
129 | * @param bool $nativeSvgSupport |
||
130 | * |
||
131 | * @return string[] all supported media types |
||
132 | */ |
||
133 | 32 | public function getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport) { |
|
152 | |||
153 | /** |
||
154 | * Returns information about the currently selected folder |
||
155 | * |
||
156 | * * privacy setting |
||
157 | * * special configuration |
||
158 | * * permissions |
||
159 | * * ID |
||
160 | * |
||
161 | * @param Folder $folderNode the current folder |
||
162 | * @param string $folderPathFromRoot path from the current folder to the virtual root |
||
163 | * @param array $features the list of features retrieved fro the configuration file |
||
164 | * |
||
165 | * @return array|null |
||
166 | * @throws ForbiddenServiceException |
||
167 | */ |
||
168 | 6 | public function getAlbumInfo($folderNode, $folderPathFromRoot, $features) { |
|
189 | |||
190 | /** |
||
191 | * Throws an exception if the media type of the file is not part of what the app allows |
||
192 | * |
||
193 | * @param $mimeType |
||
194 | * |
||
195 | * @throws ForbiddenServiceException |
||
196 | */ |
||
197 | 21 | public function validateMimeType($mimeType) { |
|
202 | |||
203 | /** |
||
204 | * Determines if we have a configuration file to work with |
||
205 | * |
||
206 | * @param Folder $rootFolder the virtual root folder |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | 6 | private function configExists($rootFolder) { |
|
213 | |||
214 | /** |
||
215 | * Adds the SVG media type if it's not already there |
||
216 | * |
||
217 | * If it's enabled, but doesn't work, an exception will be raised when trying to generate a |
||
218 | * preview. If it's disabled, we support it via the browser's native support |
||
219 | * |
||
220 | * @param string[] $supportedMimes |
||
221 | * @param bool $nativeSvgSupport |
||
222 | * |
||
223 | * @return string[] |
||
224 | */ |
||
225 | 36 | private function addSvgSupport($supportedMimes, $nativeSvgSupport) { |
|
232 | |||
233 | /** |
||
234 | * Returns true if the passed mime type is supported |
||
235 | * |
||
236 | * In case of a failure, we just return that the media type is not supported |
||
237 | * |
||
238 | * @param string $mimeType |
||
239 | * |
||
240 | * @return boolean |
||
241 | */ |
||
242 | 32 | private function isMimeSupported($mimeType = '*') { |
|
251 | |||
252 | /** |
||
253 | * Returns an album configuration array |
||
254 | * |
||
255 | * Goes through all the parent folders until either we're told the album is private or we've |
||
256 | * reached the root folder |
||
257 | * |
||
258 | * @param Folder $folder the current folder |
||
259 | * @param string $privacyChecker name of the file which blacklists folders |
||
260 | * @param string $configName name of the configuration file |
||
261 | * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder |
||
262 | * @param array $config the configuration collected so far |
||
263 | * |
||
264 | * @return array<null|array,bool> |
||
265 | */ |
||
266 | 6 | private function getAlbumConfig( |
|
287 | |||
288 | /** |
||
289 | * Returns a parsed configuration if one was found in the current folder or generates an error |
||
290 | * message to send back |
||
291 | * |
||
292 | * @param Folder $folder the current folder |
||
293 | * @param string $configName name of the configuration file |
||
294 | * @param array $config the configuration collected so far |
||
295 | * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder |
||
296 | * |
||
297 | * @return array |
||
298 | */ |
||
299 | 5 | private function buildFolderConfig($folder, $configName, $config, $level) { |
|
311 | |||
312 | /** |
||
313 | * Builds the error message to send back when there is an error |
||
314 | * |
||
315 | * @fixme Missing translation |
||
316 | * |
||
317 | * @param ConfigException $exception |
||
318 | * @param Folder $folder the current folder |
||
319 | * |
||
320 | * @return array<array<string,string>,bool> |
||
321 | */ |
||
322 | 2 | private function buildErrorMessage($exception, $folder) { |
|
336 | |||
337 | /** |
||
338 | * Removes links if they were collected outside of the virtual root |
||
339 | * |
||
340 | * This is for shared folders which have a virtual root |
||
341 | * |
||
342 | * @param array $albumConfig |
||
343 | * |
||
344 | * @return array |
||
345 | */ |
||
346 | 8 | private function validatesInfoConfig($albumConfig) { |
|
361 | |||
362 | /** |
||
363 | * Looks for an album configuration in the parent folder |
||
364 | * |
||
365 | * We will look up to the virtual root of a shared folder, for privacy reasons |
||
366 | * |
||
367 | * @param Folder $folder the current folder |
||
368 | * @param string $privacyChecker name of the file which blacklists folders |
||
369 | * @param string $configName name of the configuration file |
||
370 | * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder |
||
371 | * @param array $config the configuration collected so far |
||
372 | * |
||
373 | * @return array<null|array,bool> |
||
374 | */ |
||
375 | 1 | private function getParentConfig($folder, $privacyChecker, $configName, $level, $config) { |
|
383 | |||
384 | } |
||
385 |