From db658fac39e33001d1b38e68092e3c3aef532faf Mon Sep 17 00:00:00 2001 From: azett Date: Thu, 16 Jun 2022 12:47:03 +0200 Subject: [PATCH] Added gallery_fetch_galleries() function --- fp-includes/core/core.gallery.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/fp-includes/core/core.gallery.php b/fp-includes/core/core.gallery.php index 19f0bad..2faaa22 100644 --- a/fp-includes/core/core.gallery.php +++ b/fp-includes/core/core.gallery.php @@ -18,6 +18,36 @@ const GALLERY_CAPTIONS_FILENAME = 'captions.conf'; */ const GALLERY_CAPTIONS_LEGACYFILENAME = 'texte.conf'; +/** + * Fetches all gallery directories from the images directory and returns their names as iterative array. + * + * @return string[] the gallery names + */ +function gallery_fetch_galleries() { + $galleries = array(); + + // return empty array if there is no image dir + if (!file_exists(ABS_PATH . IMAGES_DIR)) { + return $galleries; + } + + // read folder names from image dir + $dir = opendir(ABS_PATH . IMAGES_DIR); + while (false !== ($file = readdir($dir))) { + $fullpath = ABS_PATH . IMAGES_DIR . $file; + if (!in_array($file, array( + ".", + "..", + ".thumbs" + )) && is_dir($fullpath)) { + $galleries [] = $file; + } + } + + // return result + return $galleries; +} + /** * Reads the images from the gallery directory and returns their names as iterative array *