diff --git a/lib/Controller/ArchiveController.php b/lib/Controller/ArchiveController.php index aafd0662..c3431b7f 100644 --- a/lib/Controller/ArchiveController.php +++ b/lib/Controller/ArchiveController.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace OCA\Memories\Controller; use OCA\Memories\Exceptions; -use OCA\Memories\Exif; use OCA\Memories\Util; use OCP\AppFramework\Http; use OCP\AppFramework\Http\JSONResponse; @@ -57,7 +56,7 @@ class ArchiveController extends GenericApiController } // Create archive folder in the root of the user's configured timeline - $configPaths = Exif::getTimelinePaths(Util::getUID()); + $configPaths = Util::getTimelinePaths(Util::getUID()); $timelineFolders = []; $timelinePaths = []; @@ -134,7 +133,7 @@ class ArchiveController extends GenericApiController } else { // file not in archive, put it in there $af = \OCA\Memories\Util::$ARCHIVE_FOLDER; - $destinationPath = Exif::sanitizePath($af.$relativeFilePath); + $destinationPath = Util::sanitizePath($af.$relativeFilePath); } // Remove the filename diff --git a/lib/Controller/PublicController.php b/lib/Controller/PublicController.php index 161a3ac7..12e402f0 100644 --- a/lib/Controller/PublicController.php +++ b/lib/Controller/PublicController.php @@ -5,6 +5,7 @@ namespace OCA\Memories\Controller; use OCA\Memories\AppInfo\Application; use OCA\Memories\Db\FsManager; use OCA\Memories\Db\TimelineQuery; +use OCA\Memories\Util; use OCP\AppFramework\AuthPublicShareController; use OCP\AppFramework\Http\Template\PublicTemplateResponse; use OCP\AppFramework\Http\TemplateResponse; @@ -19,7 +20,6 @@ use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Share\IManager as IShareManager; use OCP\Share\IShare; -use OCP\Util; class PublicController extends AuthPublicShareController { @@ -110,7 +110,7 @@ class PublicController extends AuthPublicShareController \OC_User::setIncognitoMode(true); // Scripts - Util::addScript($this->appName, 'memories-main'); + \OCP\Util::addScript($this->appName, 'memories-main'); PageController::provideCommonInitialState($this->initialState); // Share info @@ -125,7 +125,7 @@ class PublicController extends AuthPublicShareController // Add OG metadata $params = ['token' => $this->getToken()]; $url = $this->urlGenerator->linkToRouteAbsolute('memories.Public.showShare', $params); - \OCA\Memories\Util::addOgMetadata($node, $node->getName(), $url, $params); + Util::addOgMetadata($node, $node->getName(), $url, $params); // Render the template $response = new PublicTemplateResponse($this->appName, 'main'); @@ -195,7 +195,7 @@ class PublicController extends AuthPublicShareController // Get the user's folders path $foldersPath = $this->config->getUserValue($user->getUID(), Application::APPNAME, 'foldersPath', ''); $foldersPath = $foldersPath ?: '/'; - $foldersPath = \OCA\Memories\Exif::sanitizePath($foldersPath); + $foldersPath = Util::sanitizePath($foldersPath); // Check if relPath starts with foldersPath if (0 !== strpos($relPath, $foldersPath)) { diff --git a/lib/Db/FsManager.php b/lib/Db/FsManager.php index 8c92ec37..8b80388c 100644 --- a/lib/Db/FsManager.php +++ b/lib/Db/FsManager.php @@ -26,7 +26,6 @@ namespace OCA\Memories\Db; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; use OCA\Memories\Exceptions; -use OCA\Memories\Exif; use OCA\Memories\Util; use OCP\Files\File; use OCP\Files\Folder; @@ -103,13 +102,13 @@ class FsManager try { if (null !== $folderPath) { - $folder = $userFolder->get(Exif::sanitizePath($folderPath)); + $folder = $userFolder->get(Util::sanitizePath($folderPath)); $root->addFolder($folder); } else { // Get timeline paths - $paths = Exif::getTimelinePaths($uid); + $paths = Util::getTimelinePaths($uid); if ($path = $this->request->getParam('timelinePath', null)) { - $paths = [Exif::sanitizePath($path)]; + $paths = [Util::sanitizePath($path)]; } // Combined etag, for cache invalidation. diff --git a/lib/Exif.php b/lib/Exif.php index 835248bf..b2ed103c 100644 --- a/lib/Exif.php +++ b/lib/Exif.php @@ -7,7 +7,6 @@ namespace OCA\Memories; use OCA\Memories\AppInfo\Application; use OCA\Memories\Service\BinExt; use OCP\Files\File; -use OCP\IConfig; class Exif { @@ -65,35 +64,6 @@ class Exif } } - /** - * Get list of timeline paths as array. - */ - public static function getTimelinePaths(string $uid): array - { - $config = \OC::$server->get(IConfig::class); - $paths = $config->getUserValue($uid, Application::APPNAME, 'timelinePath', null) ?? 'Photos/'; - - return array_map(fn ($p) => self::sanitizePath(trim($p)), explode(';', $paths)); - } - - /** - * Sanitize a path to keep only ASCII characters and special characters. - */ - public static function sanitizePath(string $path) - { - $path = mb_ereg_replace('([^\\w\\s\\d\\-_~,;:!@#$&*{}\[\]\'\\[\\]\\(\\).\\\/])', '', $path); - $path = mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes - return $path; - } - - /** - * Remove any leading slash present on the path. - */ - public static function removeLeadingSlash(string $path) - { - return mb_ereg_replace('~^/+~', '', $path); - } - /** * Get exif data as a JSON object from a Nextcloud file. */ diff --git a/lib/Service/Index.php b/lib/Service/Index.php index 082fb2a4..337c7198 100644 --- a/lib/Service/Index.php +++ b/lib/Service/Index.php @@ -83,7 +83,7 @@ class Index } elseif ('1' === $mode || '0' === $mode) { // everything (or nothing) $paths = ['/']; } elseif ('2' === $mode) { // timeline - $paths = \OCA\Memories\Exif::getTimelinePaths($uid); + $paths = Util::getTimelinePaths($uid); } elseif ('3' === $mode) { // custom $paths = [Util::getSystemConfig('memories.index.path')]; } else { diff --git a/lib/Util.php b/lib/Util.php index 9246619a..18276121 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -7,6 +7,7 @@ namespace OCA\Memories; use OC\Files\Search\SearchBinaryOperator; use OC\Files\Search\SearchComparison; use OC\Files\Search\SearchQuery; +use OCA\Memories\AppInfo\Application; use OCP\App\IAppManager; use OCP\Files\Node; use OCP\Files\Search\ISearchBinaryOperator; @@ -282,6 +283,27 @@ class Util return self::getSystemConfig('memories.gis_type'); } + /** + * Get list of timeline paths as array. + */ + public static function getTimelinePaths(string $uid): array + { + $config = \OC::$server->get(IConfig::class); + $paths = $config->getUserValue($uid, Application::APPNAME, 'timelinePath', null) ?? 'Photos/'; + + return array_map(fn ($p) => self::sanitizePath(trim($p)), explode(';', $paths)); + } + + /** + * Sanitize a path to keep only ASCII characters and special characters. + */ + public static function sanitizePath(string $path) + { + $path = mb_ereg_replace('([^\\w\\s\\d\\-_~,;:!@#$&*{}\[\]\'\\[\\]\\(\\).\\\/])', '', $path); + + return mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes + } + /** * Get a system config key with the correct default. *