fonction getModules

This commit is contained in:
Prof Langues 2021-02-09 18:04:24 +01:00
parent 4fb0528ea5
commit dde3a1c6a2
19 changed files with 69 additions and 47 deletions

View File

@ -127,6 +127,41 @@ class helper {
return ($fileName);
}
/**
* Retourne la liste des modules installés dans un tableau composé
* du nom réel
* du numéro de version
*/
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';
}
// Affection
$modules [$value] = [
'realName' => $realName,
'version' => $version
];
}
return($modules);
}
/**
* Retourne true si le protocole est en TLS
* @return bool

View File

@ -604,6 +604,7 @@ class config extends common {
*/
public function modules() {
helper::getModules();
// Préparation du tableau des modules installés
// Liste des modules installés (répertoire de module/)
if ($dh = opendir( 'module/' )) {
@ -613,12 +614,12 @@ class config extends common {
self::$modInstal[$i][0] = $dirmodule;
self::$modInstal[$i][1] = page::$moduleNames[$dirmodule];
// Lecture de la version pour les modules officiels et distribués
$blogversion = blog::BLOG_VERSION;
$formversion = form::FORM_VERSION;
$galleryversion = gallery::GALLERY_VERSION;
$newsversion = news::NEWS_VERSION;
$redirectionversion = redirection::REDIRECTION_VERSION;
$searchversion = search::SEARCH_VERSION;
$blogversion = blog::VERSION;
$formversion = form::VERSION;
$galleryversion = gallery::VERSION;
$newsversion = news::VERSION;
$redirectionversion = redirection::VERSION;
$searchversion = search::VERSION;
self::$str = $dirmodule.'version';
self::$modInstal[$i][2] = '?';
if( ${self::$str} !== null){

View File

@ -29,15 +29,7 @@ class page extends common {
'' => 'Aucune'
];
public static $moduleIds = [];
// Nom des modules
public static $moduleNames = [
'news' => 'Nouvelles',
'blog' => 'Blog',
'form' => 'Formulaire',
'gallery' => 'Galerie',
'redirection' => 'Redirection',
'search' => 'Recherche'
];
public static $typeMenu = [
'text' => 'Texte',
'icon' => 'Icône',
@ -448,22 +440,8 @@ class page extends common {
'state' => true
]);
}
}
// Liste des modules
$moduleIds = [];
$iterator = new DirectoryIterator('module/');
foreach($iterator as $fileInfos) {
if(is_file($fileInfos->getPathname() . '/' . $fileInfos->getFilename() . '.php')) {
if (array_key_exists($fileInfos->getBasename(),self::$moduleNames)) {
$moduleIds[$fileInfos->getBasename()] = self::$moduleNames[$fileInfos->getBasename()];
} else {
$moduleIds[$fileInfos->getBasename()] = ucfirst($fileInfos->getBasename());
}
}
}
self::$moduleIds = $moduleIds;
asort(self::$moduleIds);
self::$moduleIds = array_merge( ['' => 'Aucun'] , self::$moduleIds);
}
self::$moduleIds = array_merge( ['' => 'Aucun'] , helper::arrayCollumn(helper::getModules(),'realName','SORT_ASC'));
// Pages sans parent
foreach($this->getHierarchy() as $parentPageId => $childrenPageIds) {
if($parentPageId !== $this->getUrl(2)) {

View File

@ -54,7 +54,7 @@ echo template::formOpen('pageEditForm');
]); ?>
<?php echo template::hidden('pageEditModuleIdOld',['value' => $this->getData(['page', $this->getUrl(2), 'moduleId'])]); ?>
<?php echo template::hidden('pageEditModuleIdOldText',[
'value' => array_key_exists($this->getData(['page', $this->getUrl(2), 'moduleId']),$module::$moduleNames)? $module::$moduleNames[$this->getData(['page', $this->getUrl(2), 'moduleId'])] : ucfirst($this->getData(['page', $this->getUrl(2), 'moduleId']))
'value' => array_key_exists($this->getData(['page', $this->getUrl(2), 'moduleId']),$module::$moduleIds)? $module::$moduleIds[$this->getData(['page', $this->getUrl(2), 'moduleId'])] : ucfirst($this->getData(['page', $this->getUrl(2), 'moduleId']))
]); ?>
</div>
<div class="col3 verticalAlignBottom">

View File

@ -87,7 +87,8 @@ class blog extends common {
public static $users = [];
const BLOG_VERSION = '4.2';
const VERSION = '4.2';
const REALNAME = 'Blog';
/**
* Flux RSS

View File

@ -47,6 +47,6 @@
<?php echo template::speech('Aucun article.'); ?>
<?php endif; ?>
<div class="moduleVersion">Version
<?php echo $module::BLOG_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>

View File

@ -32,7 +32,8 @@ class form extends common {
public static $pagination;
const FORM_VERSION = '2.7';
const VERSION = '2.7';
const REALNAME = 'Formulaire';
// Objets
const TYPE_MAIL = 'mail';

View File

@ -164,5 +164,5 @@
</div>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version
<?php echo $module::FORM_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>

View File

@ -26,5 +26,5 @@
<?php echo template::table([11, 1], $module::$data, ['Données', '']); ?>
<?php echo $module::$pagination; ?>
<div class="moduleVersion">Version
<?php echo $module::FORM_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>

View File

@ -19,7 +19,9 @@ class gallery extends common {
const SORT_ASC = 'SORT_ASC';
const SORT_DSC = 'SORT_DSC';
const SORT_HAND = 'SORT_HAND';
const GALLERY_VERSION = '2.5';
const VERSION = '2.5';
const REALNAME = 'Galerie';
public static $directories = [];

View File

@ -58,6 +58,6 @@
<?php endif; ?>
</div>
<div class="moduleVersion">Version
<?php echo $module::GALLERY_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>
</div>

View File

@ -64,6 +64,6 @@
</div>
<div class="moduleVersion">Version
<?php echo $module::GALLERY_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>
<?php echo template::formClose(); ?>

View File

@ -139,7 +139,7 @@
<div class="row">
<div class="col12">
<div class="moduleVersion">Version
<?php echo $module::GALLERY_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>
</div>
</div>

View File

@ -33,10 +33,12 @@ class news extends common {
false => 'Brouillon',
true => 'Publié'
];
const NEWS_VERSION = '2.0';
public static $users = [];
const VERSION = '2.0';
const REALNAME = 'Nouvelles';
/**
* Flux RSS
*/

View File

@ -48,5 +48,5 @@
<?php endif; ?>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version
<?php echo $module::NEWS_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>

View File

@ -19,7 +19,8 @@ class redirection extends common {
'index' => self::GROUP_VISITOR
];
const REDIRECTION_VERSION = '1.4';
const VERSION = '1.4';
const REALNAME = 'Redirection';
/**
* Configuration

View File

@ -37,5 +37,5 @@
</div>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version
<?php echo $module::REDIRECTION_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>

View File

@ -38,7 +38,8 @@ class search extends common {
400 => '400 caractères',
];
const SEARCH_VERSION = '1.2';
const VERSION = '1.2';
const REALNAME = 'Recherche';
// Configuration vide
public function config() {

View File

@ -68,5 +68,5 @@
</div>
<?php echo template::formClose(); ?>
<div class="moduleVersion">Version
<?php echo $module::SEARCH_VERSION; ?>
<?php echo $module::VERSION; ?>
</div>