From 5616b7a065631b91cde4cc5afe38a1a1f1f2a74b Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Tue, 28 May 2019 20:52:23 -0400 Subject: [PATCH 1/4] Added .noimage functionality Signed-off-by: Thomas Anderson --- lib/Service/ConfigService.php | 18 ++++++++++-------- lib/Service/FilesService.php | 12 +++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/Service/ConfigService.php b/lib/Service/ConfigService.php index 4ec2b6251..429bfd748 100644 --- a/lib/Service/ConfigService.php +++ b/lib/Service/ConfigService.php @@ -159,7 +159,7 @@ public function getSupportedMediaTypes($extraMediaTypes, $nativeSvgSupport) { public function getConfig($folderNode, $features) { $this->features = $features; list ($albumConfig, $ignored) = - $this->collectConfig($folderNode, $this->ignoreAlbum, $this->configName); + $this->collectConfig($folderNode, $this->ignoreAlbumStrings, $this->configName); if ($ignored) { throw new ForbiddenServiceException( 'The owner has placed a restriction or the storage location is unavailable' @@ -238,7 +238,7 @@ private function isMimeSupported($mimeType = '*') { * reached the root folder * * @param Folder $folder the current folder - * @param string $ignoreAlbum name of the file which blacklists folders + * @param array $ignoreAlbumStrings names of the files which blacklist folders * @param string $configName name of the configuration file * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder * @param array $configSoFar the configuration collected so far @@ -246,18 +246,20 @@ private function isMimeSupported($mimeType = '*') { * @return array */ private function collectConfig( - $folder, $ignoreAlbum, $configName, $level = 0, $configSoFar = [] + $folder, $ignoreAlbumStrings, $configName, $level = 0, $configSoFar = [] ) { - if ($folder->nodeExists($ignoreAlbum)) { - // Cancel as soon as we find out that the folder is private or external - return [null, true]; + foreach ($ignoreAlbumStrings as $ignoreAlbum) { + if ($folder->nodeExists($ignoreAlbum)) { + // Cancel as soon as we find out that the folder is private or external + return [null, true]; + } } $isRootFolder = $this->isRootFolder($folder, $level); if ($folder->nodeExists($configName)) { $configSoFar = $this->buildFolderConfig($folder, $configName, $configSoFar, $level); } if (!$isRootFolder) { - return $this->getParentConfig($folder, $ignoreAlbum, $configName, $level, $configSoFar); + return $this->getParentConfig($folder, $ignoreAlbumStrings, $configName, $level, $configSoFar); } $configSoFar = $this->validatesInfoConfig($configSoFar); @@ -345,7 +347,7 @@ private function validatesInfoConfig($albumConfig) { * We will look up to the virtual root of a shared folder, for privacy reasons * * @param Folder $folder the current folder - * @param string $privacyChecker name of the file which blacklists folders + * @param string $privacyChecker names of the files which blacklist folders * @param string $configName name of the configuration file * @param int $level the starting level is 0 and we add 1 each time we visit a parent folder * @param array $collectedConfig the configuration collected so far diff --git a/lib/Service/FilesService.php b/lib/Service/FilesService.php index e88ebe520..e9321785d 100644 --- a/lib/Service/FilesService.php +++ b/lib/Service/FilesService.php @@ -28,8 +28,8 @@ abstract class FilesService extends Service { protected $virtualRootLevel = null; /** @var string[] */ protected $features; - /** @var string */ - protected $ignoreAlbum = '.nomedia'; + /** @var string[] */ + protected $ignoreAlbumStrings = array('.nomedia', '.noimage'); /** * Retrieves all files and sub-folders contained in a folder @@ -141,10 +141,16 @@ protected function getFolderData($node) { * @return array|Folder */ protected function getAllowedSubFolder($node, $nodeType) { + $ignored = false; if ($nodeType === 'dir') { /** @var Folder $node */ try { - if (!$node->nodeExists($this->ignoreAlbum)) { + foreach ($this->ignoreAlbumStrings as $ignoreAlbum) { + if ($node->nodeExists($ignoreAlbum)) { + $ignored = true; + } + } + if (!$ignored) { return [$node]; } } catch (StorageNotAvailableException $e) { From 7aa9dac064e7df096d7487c063e07a5da012bd3d Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Tue, 28 May 2019 20:57:05 -0400 Subject: [PATCH 2/4] Update documentation Signed-off-by: Thomas Anderson --- README.md | 4 ++-- appinfo/info.xml | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 96ded46ff..604385fa9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Gallery +# Gallery [![Build Status](https://travis-ci.org/nextcloud/gallery.svg?branch=master)](https://travis-ci.org/nextcloud/gallery) [![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) [![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 * A la carte features (external shares, browser svg rendering, etc.) * Image download and sharing straight from the slideshow or the gallery * Switch to Gallery from any folder in files and vice-versa -* Ignore folders containing a ".nomedia" file +* Ignore folders containing a ".nomedia" or ".noimage" file * Browser rendering of SVG images (disabled by default) * Mobile support diff --git a/appinfo/info.xml b/appinfo/info.xml index 22c1ad05b..e271b5a02 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,7 +22,7 @@ - Switch to Gallery from any folder in files and vice-versa - - Ignore folders containing a ".nomedia" file + - Ignore folders containing a ".nomedia" or ".noimage" file - Browser rendering of SVG images (disabled by default) @@ -55,4 +55,3 @@ https://github.com/nextcloud/gallery/wiki - From 2d26d2b6323207377a2d7f9cd4ec954b63346c77 Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Tue, 28 May 2019 21:46:41 -0400 Subject: [PATCH 3/4] Efficiency improvements Signed-off-by: Thomas Anderson --- lib/Service/FilesService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Service/FilesService.php b/lib/Service/FilesService.php index e9321785d..99c57b436 100644 --- a/lib/Service/FilesService.php +++ b/lib/Service/FilesService.php @@ -148,6 +148,7 @@ protected function getAllowedSubFolder($node, $nodeType) { foreach ($this->ignoreAlbumStrings as $ignoreAlbum) { if ($node->nodeExists($ignoreAlbum)) { $ignored = true; + break; } } if (!$ignored) { From 51279a8f5cd3c35899e5c1b37846f7f0b7828b99 Mon Sep 17 00:00:00 2001 From: Thomas Anderson Date: Thu, 27 Jun 2019 22:38:54 -0400 Subject: [PATCH 4/4] Suggested changes from nickvergessen Signed-off-by: Thomas Anderson --- lib/Service/FilesService.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Service/FilesService.php b/lib/Service/FilesService.php index 99c57b436..6c843fef2 100644 --- a/lib/Service/FilesService.php +++ b/lib/Service/FilesService.php @@ -29,7 +29,7 @@ abstract class FilesService extends Service { /** @var string[] */ protected $features; /** @var string[] */ - protected $ignoreAlbumStrings = array('.nomedia', '.noimage'); + protected $ignoreAlbumStrings = ['.nomedia', '.noimage']; /** * Retrieves all files and sub-folders contained in a folder @@ -141,19 +141,15 @@ protected function getFolderData($node) { * @return array|Folder */ protected function getAllowedSubFolder($node, $nodeType) { - $ignored = false; if ($nodeType === 'dir') { /** @var Folder $node */ try { foreach ($this->ignoreAlbumStrings as $ignoreAlbum) { if ($node->nodeExists($ignoreAlbum)) { - $ignored = true; - break; + return []; } } - if (!$ignored) { - return [$node]; - } + return [$node]; } catch (StorageNotAvailableException $e) { return []; }