Browse Source

scanSubDir and check empty folder

10504
Prof Langues 7 months ago
parent
commit
3f68897639
  1. 59
      core/class/helper.class.php
  2. 22
      module/gallery/gallery.php

59
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);
}
// Constante VERSION
if (array_key_exists('VERSION', $class_constants)) {
$version = $value::VERSION;
} else {
$version = '0.0';
// 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
];
}
// 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

22
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;
}
}
Loading…
Cancel
Save