Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit 0f94c96

Browse files
authored
Merge pull request #533 from nextcloud/backport/520/stable16
[stable16] Blacklist using .noimage
2 parents 3f22945 + 21beed6 commit 0f94c96

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Gallery
1+
# Gallery
22
[![Build Status](https://travis-ci.org/nextcloud/gallery.svg?branch=master)](https://travis-ci.org/nextcloud/gallery)
33
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nextcloud/gallery/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nextcloud/gallery/?branch=master)
44
[![Code Coverage](https://codecov.io/gh/nextcloud/gallery/branch/master/graph/badge.svg)](https://codecov.io/gh/nextcloud/gallery)
@@ -20,7 +20,7 @@ Provides a dedicated view of all images in a grid, adds image viewing capabiliti
2020
* A la carte features (external shares, browser svg rendering, etc.)
2121
* Image download and sharing straight from the slideshow or the gallery
2222
* Switch to Gallery from any folder in files and vice-versa
23-
* Ignore folders containing a ".nomedia" file
23+
* Ignore folders containing a ".nomedia" or ".noimage" file
2424
* Browser rendering of SVG images (disabled by default)
2525
* Mobile support
2626

appinfo/info.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
- Switch to Gallery from any folder in files and vice-versa
2424

25-
- Ignore folders containing a ".nomedia" file
25+
- Ignore folders containing a ".nomedia" or ".noimage" file
2626

2727
- Browser rendering of SVG images (disabled by default)
2828

@@ -55,4 +55,3 @@
5555
<developer>https://github.com/nextcloud/gallery/wiki</developer>
5656
</documentation>
5757
</info>
58-

lib/Service/ConfigService.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport) {
159159
public function getConfig($folderNode, $features) {
160160
$this->features = $features;
161161
list ($albumConfig, $ignored) =
162-
$this->collectConfig($folderNode, $this->ignoreAlbum, $this->configName);
162+
$this->collectConfig($folderNode, $this->ignoreAlbumStrings, $this->configName);
163163
if ($ignored) {
164164
throw new ForbiddenServiceException(
165165
'The owner has placed a restriction or the storage location is unavailable'
@@ -238,26 +238,28 @@ private function isMimeSupported($mimeType = '*') {
238238
* reached the root folder
239239
*
240240
* @param Folder $folder the current folder
241-
* @param string $ignoreAlbum name of the file which blacklists folders
241+
* @param array $ignoreAlbumStrings names of the files which blacklist folders
242242
* @param string $configName name of the configuration file
243243
* @param int $level the starting level is 0 and we add 1 each time we visit a parent folder
244244
* @param array $configSoFar the configuration collected so far
245245
*
246246
* @return array <null|array,bool>
247247
*/
248248
private function collectConfig(
249-
$folder, $ignoreAlbum, $configName, $level = 0, $configSoFar = []
249+
$folder, $ignoreAlbumStrings, $configName, $level = 0, $configSoFar = []
250250
) {
251-
if ($folder->nodeExists($ignoreAlbum)) {
252-
// Cancel as soon as we find out that the folder is private or external
253-
return [null, true];
251+
foreach ($ignoreAlbumStrings as $ignoreAlbum) {
252+
if ($folder->nodeExists($ignoreAlbum)) {
253+
// Cancel as soon as we find out that the folder is private or external
254+
return [null, true];
255+
}
254256
}
255257
$isRootFolder = $this->isRootFolder($folder, $level);
256258
if ($folder->nodeExists($configName)) {
257259
$configSoFar = $this->buildFolderConfig($folder, $configName, $configSoFar, $level);
258260
}
259261
if (!$isRootFolder) {
260-
return $this->getParentConfig($folder, $ignoreAlbum, $configName, $level, $configSoFar);
262+
return $this->getParentConfig($folder, $ignoreAlbumStrings, $configName, $level, $configSoFar);
261263
}
262264
$configSoFar = $this->validatesInfoConfig($configSoFar);
263265

@@ -345,7 +347,7 @@ private function validatesInfoConfig($albumConfig) {
345347
* We will look up to the virtual root of a shared folder, for privacy reasons
346348
*
347349
* @param Folder $folder the current folder
348-
* @param string $privacyChecker name of the file which blacklists folders
350+
* @param string $privacyChecker names of the files which blacklist folders
349351
* @param string $configName name of the configuration file
350352
* @param int $level the starting level is 0 and we add 1 each time we visit a parent folder
351353
* @param array $collectedConfig the configuration collected so far

lib/Service/FilesService.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ abstract class FilesService extends Service {
2828
protected $virtualRootLevel = null;
2929
/** @var string[] */
3030
protected $features;
31-
/** @var string */
32-
protected $ignoreAlbum = '.nomedia';
31+
/** @var string[] */
32+
protected $ignoreAlbumStrings = ['.nomedia', '.noimage'];
3333

3434
/**
3535
* Retrieves all files and sub-folders contained in a folder
@@ -144,9 +144,12 @@ protected function getAllowedSubFolder($node, $nodeType) {
144144
if ($nodeType === 'dir') {
145145
/** @var Folder $node */
146146
try {
147-
if (!$node->nodeExists($this->ignoreAlbum)) {
148-
return [$node];
147+
foreach ($this->ignoreAlbumStrings as $ignoreAlbum) {
148+
if ($node->nodeExists($ignoreAlbum)) {
149+
return [];
150+
}
149151
}
152+
return [$node];
150153
} catch (StorageNotAvailableException $e) {
151154
return [];
152155
}

0 commit comments

Comments
 (0)