| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * ownCloud - galleryplus | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * later. See the COPYING file. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author Olivier Paroz <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @copyright Olivier Paroz 2015 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | namespace OCA\GalleryPlus\Service; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use OCP\Template; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use OCP\Files\Folder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use OCP\ILogger; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use OCA\GalleryPlus\Config\ConfigParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use OCA\GalleryPlus\Config\ConfigException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use OCA\GalleryPlus\Environment\Environment; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use OCA\GalleryPlus\Preview\Preview; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * Finds configurations files and returns a configuration array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * Checks the current and parent folders for configuration files and to see if we're allowed to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * look for media file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * Supports explicit inheritance | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @package OCA\GalleryPlus\Service | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | class ConfigService extends FilesService { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	/** @var string */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	private $configName = 'gallery.cnf'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	/** @var array <string,bool> */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	private $completionStatus = ['design' => false, 'information' => false, 'sorting' => false]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	/** @var ConfigParser */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	private $configParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	/** @var Preview */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	private $previewManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * @todo This hard-coded array could be replaced by admin settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * @var string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	private $baseMimeTypes = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 		'image/png', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		'image/jpeg', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | 		'image/gif', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		'image/x-xbitmap', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		'image/bmp', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 		'image/tiff', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		'image/x-dcraw', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		'application/x-photoshop', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		'application/illustrator', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		'application/postscript', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 	]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 	 * These types are useful for files preview in the files app, but | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	 * not for the gallery side | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * @var string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	private $slideshowMimeTypes = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		'application/font-sfnt', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 		'application/x-font', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 	 * Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | 	 * @param string $appName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 	 * @param Environment $environment | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	 * @param ConfigParser $configParser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * @param Preview $previewManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * @param ILogger $logger | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 		$appName, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		Environment $environment, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 		ConfigParser $configParser, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 		Preview $previewManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		ILogger $logger | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		parent::__construct($appName, $environment, $logger); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 57 |  | 		$this->configParser = $configParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 		$this->previewManager = $previewManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	 * Returns a list of supported features | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 57 |  | 	 * @return string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 | 57 |  | 	public function getFeaturesList() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 57 |  | 		$featuresList = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 57 |  | 		/** @var Folder $rootFolder */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$rootFolder = $this->environment->getVirtualRootFolder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 		if ($this->isAllowedAndAvailable($rootFolder) && $this->configExists($rootFolder)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 			try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 				$featuresList = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 					$this->configParser->getFeaturesList($rootFolder, $this->configName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 			} catch (ConfigException $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 6 |  | 				$featuresList = $this->buildErrorMessage($exception, $rootFolder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 | 6 |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 | 6 |  | 		return $featuresList; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 | 5 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 | 5 |  | 	 * This builds and returns a list of all supported media types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 | 1 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 	 * @todo Native SVG could be disabled via admin settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 	 * @param bool $extraMediaTypes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 | 6 |  | 	 * @param bool $nativeSvgSupport | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	 * @return string[] all supported media types | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	public function getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 		$supportedMimes = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		$wantedMimes = $this->baseMimeTypes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | 		if ($extraMediaTypes) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 			$wantedMimes = array_merge($wantedMimes, $this->slideshowMimeTypes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 		foreach ($wantedMimes as $wantedMime) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 			// Let's see if a preview of files of that media type can be generated | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 			if ($this->isMimeSupported($wantedMime)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 | 32 |  | 				// We store the media type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 | 32 |  | 				$supportedMimes[] = $wantedMime; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 | 32 |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 | 32 |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 | 24 |  | 		$supportedMimes = $this->addSvgSupport($supportedMimes, $nativeSvgSupport); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 13 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 | 32 |  | 		//$this->logger->debug("Supported Mimes: {mimes}", ['mimes' => $supportedMimes]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 | 32 |  | 		return $supportedMimes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 | 31 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 | 15 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 | 32 |  | 	 * Returns the configuration of the currently selected folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 | 32 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	 *    * information (description, copyright) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 	 *    * sorting (date, name, inheritance) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  | 	 *    * design (colour) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 | 32 |  | 	 *    * if the album should be ignored | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 	 * @param Folder $folderNode the current folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  | 	 * @param array $features the list of features retrieved fro the configuration file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 	 * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | 	 * @throws ForbiddenServiceException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 	public function getConfig($folderNode, $features) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 		$this->features = $features; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 		list ($albumConfig, $ignored) = | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 			$this->collectConfig($folderNode, $this->ignoreAlbum, $this->configName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 		if ($ignored) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 			throw new ForbiddenServiceException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  | 				'The owner has placed a restriction or the storage location is unavailable' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 | 6 |  | 		return $albumConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 | 6 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 | 6 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 6 |  | 	 * Throws an exception if the media type of the file is not part of what the app allows | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 | 1 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | 	 * @param $mimeType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 | 5 |  | 	 * @throws ForbiddenServiceException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 | 5 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 | 5 |  | 	public function validateMimeType($mimeType) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 5 |  | 		if (!in_array($mimeType, $this->getSupportedMediaTypes(true, true))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 5 |  | 			throw new ForbiddenServiceException('Media type not allowed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 5 |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 | 5 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  | 	 * Determines if we have a configuration file to work with | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  | 	 * @param Folder $rootFolder the virtual root folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | 	 * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 190 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 191 |  |  | 	private function configExists($rootFolder) { | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  | 		return $rootFolder && $rootFolder->nodeExists($this->configName); | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 | 21 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 | 21 |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 | 6 |  | 	 * Adds the SVG media type if it's not already there | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 | 15 |  | 	 * If it's enabled, but doesn't work, an exception will be raised when trying to generate a | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  | 	 * preview. If it's disabled, we support it via the browser's native support | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  | 	 * @param string[] $supportedMimes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  | 	 * @param bool $nativeSvgSupport | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  | 	 * @return string[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  | 	private function addSvgSupport($supportedMimes, $nativeSvgSupport) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 | 6 |  | 		if (!in_array('image/svg+xml', $supportedMimes) && $nativeSvgSupport) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 | 6 |  | 			$supportedMimes[] = 'image/svg+xml'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  | 		return $supportedMimes; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  | 	 * Returns true if the passed mime type is supported | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  | 	 * In case of a failure, we just return that the media type is not supported | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  | 	 * @param string $mimeType | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  | 	 * @return boolean | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 | 36 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 | 36 |  | 	private function isMimeSupported($mimeType = '*') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 | 24 |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 | 14 |  | 			return $this->previewManager->isMimeSupported($mimeType); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  | 		} catch (\Exception $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 | 36 |  | 			unset($exception); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  | 			return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  | 	 * Returns an album configuration array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | 	 * Goes through all the parent folders until either we're told the album is private or we've | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  | 	 * reached the root folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 | 32 |  | 	 * @param Folder $folder the current folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  | 	 * @param string $ignoreAlbum name of the file which blacklists folders | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 | 32 |  | 	 * @param string $configName name of the configuration file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 | 1 |  | 	 * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 | 1 |  | 	 * @param array $configSoFar the configuration collected so far | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 | 1 |  | 	 * @return array <null|array,bool> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  | 	private function collectConfig( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  | 		$folder, $ignoreAlbum, $configName, $level = 0, $configSoFar = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  | 		if ($folder->nodeExists($ignoreAlbum)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  | 			// Cancel as soon as we find out that the folder is private or external | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  | 			return [null, true]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 		$isRootFolder = $this->isRootFolder($folder, $level); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | 		if ($folder->nodeExists($configName)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | 			$configSoFar = $this->buildFolderConfig($folder, $configName, $configSoFar, $level); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  | 		if (!$isRootFolder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  | 			return $this->getParentConfig($folder, $ignoreAlbum, $configName, $level, $configSoFar); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  | 		$configSoFar = $this->validatesInfoConfig($configSoFar); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 | 6 |  | 		// We have reached the root folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  | 		return [$configSoFar, false]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 | 1 |  | 	 * Returns a parsed configuration if one was found in the current folder or generates an error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  | 	 * message to send back | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 | 5 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 | 5 |  | 	 * @param Folder $folder the current folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 | 4 |  | 	 * @param string $configName name of the configuration file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  | 	 * @param array $collectedConfig the configuration collected so far | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 | 5 |  | 	 * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 | 1 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 | 1 |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 | 1 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  | 	private function buildFolderConfig($folder, $configName, $collectedConfig, $level) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 | 5 |  | 		try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  | 			list($collectedConfig, $completionStatus) = $this->configParser->getFolderConfig( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  | 				$folder, $configName, $collectedConfig, $this->completionStatus, $level | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 5 |  | 			); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  | 			$this->completionStatus = $completionStatus; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  | 		} catch (ConfigException $exception) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  | 			$collectedConfig = $this->buildErrorMessage($exception, $folder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  | 		return $collectedConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  | 	 * Builds the error message to send back when there is an error | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  | 	 * @fixme Missing translation | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 | 5 |  | 	 * @param ConfigException $exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  | 	 * @param Folder $folder the current folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 | 5 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 | 5 |  | 	 * @return array<array<string,string>,bool> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 | 5 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 | 4 |  | 	private function buildErrorMessage($exception, $folder) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 | 5 |  | 		$configPath = $this->environment->getPathFromVirtualRoot($folder); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 | 1 |  | 		$errorMessage = $exception->getMessage() . ". Config location: /$configPath"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  | 		$this->logger->error($errorMessage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  | 		$config = ['error' => ['message' => $errorMessage]]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 | 5 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  | 		$completionStatus = $this->completionStatus; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  | 		foreach ($completionStatus as $key) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  | 			$completionStatus[$key] = true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  | 		$this->completionStatus = $completionStatus; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  | 		return [$config]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  | 	 * Removes links if they were collected outside of the virtual root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 | 2 |  | 	 * This is for shared folders which have a virtual root | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 | 2 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 | 2 |  | 	 * @param array $albumConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 | 2 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 | 2 |  | 	 * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 | 2 |  | 	private function validatesInfoConfig($albumConfig) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 | 2 |  | 		$this->virtualRootLevel; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 | 2 |  | 		if (array_key_exists('information', $albumConfig)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 | 2 |  | 			$info = $albumConfig['information']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 | 2 |  | 			if (array_key_exists('level', $info)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  | 				$level = $info['level']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 | 2 |  | 				if ($level > $this->virtualRootLevel) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  | 					$albumConfig['information']['description_link'] = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  | 					$albumConfig['information']['copyright_link'] = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | 		return $albumConfig; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | 	 * Looks for an album configuration in the parent folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 | 8 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 344 | 8 |  | 	 * We will look up to the virtual root of a shared folder, for privacy reasons | 
            
                                                                                                            
                            
            
                                    
            
            
                | 345 | 8 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 346 | 7 |  | 	 * @param Folder $folder the current folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 347 | 7 |  | 	 * @param string $privacyChecker name of the file which blacklists folders | 
            
                                                                                                            
                            
            
                                    
            
            
                | 348 | 7 |  | 	 * @param string $configName name of the configuration file | 
            
                                                                                                            
                            
            
                                    
            
            
                | 349 | 7 |  | 	 * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 350 | 1 |  | 	 * @param array $collectedConfig the configuration collected so far | 
            
                                                                                                            
                            
            
                                    
            
            
                | 351 | 1 |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 352 | 1 |  | 	 * @return array<null|array,bool> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 353 | 3 |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 354 | 3 |  | 	private function getParentConfig($folder, $privacyChecker, $configName, $level, $collectedConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 355 |  |  | 	) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 356 | 8 |  | 		$parentFolder = $folder->getParent(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 357 |  |  | 		$level++; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 358 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 359 |  |  | 		return $this->collectConfig( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 360 |  |  | 			$parentFolder, $privacyChecker, $configName, $level, $collectedConfig | 
            
                                                                                                            
                            
            
                                    
            
            
                | 361 |  |  | 		); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 362 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 363 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 364 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 365 |  |  |  |