From 3f6889763923787f1738fe7fdb20618001fcffb9 Mon Sep 17 00:00:00 2001 From: Prof Langues Date: Wed, 10 Feb 2021 16:59:17 +0100 Subject: [PATCH] scanSubDir and check empty folder --- core/class/helper.class.php | 59 +++++++++++++++++++++++++------------ module/gallery/gallery.php | 22 +------------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 4ce97ef5..3505241e 100755 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -137,30 +137,51 @@ class helper { public static function getModules() { $dirs = array_diff(scandir('module'), array('..', '.')); foreach ($dirs as $key => $value) { - // Lire les constantes - $class_reflex = new \ReflectionClass($value); - $class_constants = $class_reflex->getConstants(); - // Constante REALNAME - if (array_key_exists('REALNAME', $class_constants)) { - $realName = $value::REALNAME; - } else { - $realName = ucfirst($value); + // Dossier non vide + if (file_exists('module/' . $value . '/' . $value . '.php')) { + // Lire les constantes + $class_reflex = new \ReflectionClass($value); + $class_constants = $class_reflex->getConstants(); + // Constante REALNAME + if (array_key_exists('REALNAME', $class_constants)) { + $realName = $value::REALNAME; + } else { + $realName = ucfirst($value); + } + // Constante VERSION + if (array_key_exists('VERSION', $class_constants)) { + $version = $value::VERSION; + } else { + $version = '0.0'; + } + // Affection + $modules [$value] = [ + 'realName' => $realName, + 'version' => $version + ]; } - // Constante VERSION - if (array_key_exists('VERSION', $class_constants)) { - $version = $value::VERSION; - } else { - $version = '0.0'; - } - // Affection - $modules [$value] = [ - 'realName' => $realName, - 'version' => $version - ]; } return($modules); } + + /** + * Scanne le contenu d'un dossier et de ses sous-dossiers + * @param string $dir Dossier à scanner + * @return array + */ + public static function scanSubDir($dir) { + $dirContent = []; + $iterator = new DirectoryIterator($dir); + foreach($iterator as $fileInfos) { + if($fileInfos->isDot() === false AND $fileInfos->isDir()) { + $dirContent[] = $dir . '/' . $fileInfos->getBasename(); + $dirContent = array_merge($dirContent, self::scanSubDir($dir . '/' . $fileInfos->getBasename())); + } + } + return $dirContent; + } + /** * Retourne true si le protocole est en TLS diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index e8526b7c..7156931c 100755 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -324,7 +324,7 @@ class gallery extends common { // Valeurs en sortie $this->addOutput([ 'display' => self::DISPLAY_JSON, - 'content' => galleriesHelper::scanDir(self::FILE_DIR.'source') + 'content' => helper::scanSubDir(self::FILE_DIR.'source') ]); } @@ -673,24 +673,4 @@ class gallery extends common { ]); } -} - -class galleriesHelper extends helper { - - /** - * Scan le contenu d'un dossier et de ses sous-dossiers - * @param string $dir Dossier à scanner - * @return array - */ - public static function scanDir($dir) { - $dirContent = []; - $iterator = new DirectoryIterator($dir); - foreach($iterator as $fileInfos) { - if($fileInfos->isDot() === false AND $fileInfos->isDir()) { - $dirContent[] = $dir . '/' . $fileInfos->getBasename(); - $dirContent = array_merge($dirContent, self::scanDir($dir . '/' . $fileInfos->getBasename())); - } - } - return $dirContent; - } } \ No newline at end of file