From dde3a1c6a2a2d5f3523005b6adedbc1d173da05a Mon Sep 17 00:00:00 2001 From: Prof Langues Date: Tue, 9 Feb 2021 18:04:24 +0100 Subject: [PATCH] fonction getModules --- core/class/helper.class.php | 35 +++++++++++++++++++++++ core/module/config/config.php | 13 +++++---- core/module/page/page.php | 28 ++---------------- core/module/page/view/edit/edit.php | 2 +- module/blog/blog.php | 3 +- module/blog/view/config/config.php | 2 +- module/form/form.php | 3 +- module/form/view/config/config.php | 2 +- module/form/view/data/data.php | 2 +- module/gallery/gallery.php | 4 ++- module/gallery/view/config/config.php | 2 +- module/gallery/view/edit/edit.php | 2 +- module/gallery/view/theme/theme.php | 2 +- module/news/news.php | 4 ++- module/news/view/config/config.php | 2 +- module/redirection/redirection.php | 3 +- module/redirection/view/config/config.php | 2 +- module/search/search.php | 3 +- module/search/view/config/config.php | 2 +- 19 files changed, 69 insertions(+), 47 deletions(-) diff --git a/core/class/helper.class.php b/core/class/helper.class.php index 396208ec..4ce97ef5 100755 --- a/core/class/helper.class.php +++ b/core/class/helper.class.php @@ -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 diff --git a/core/module/config/config.php b/core/module/config/config.php index 5036f1de..79c03d23 100755 --- a/core/module/config/config.php +++ b/core/module/config/config.php @@ -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){ diff --git a/core/module/page/page.php b/core/module/page/page.php index 88e6b37f..f59c79b5 100755 --- a/core/module/page/page.php +++ b/core/module/page/page.php @@ -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)) { diff --git a/core/module/page/view/edit/edit.php b/core/module/page/view/edit/edit.php index cac97d04..be3941f2 100755 --- a/core/module/page/view/edit/edit.php +++ b/core/module/page/view/edit/edit.php @@ -54,7 +54,7 @@ echo template::formOpen('pageEditForm'); ]); ?> $this->getData(['page', $this->getUrl(2), 'moduleId'])]); ?> 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'])) ]); ?>
diff --git a/module/blog/blog.php b/module/blog/blog.php index 110d92f0..6b83a8db 100755 --- a/module/blog/blog.php +++ b/module/blog/blog.php @@ -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 diff --git a/module/blog/view/config/config.php b/module/blog/view/config/config.php index 7830d8fd..fee5671a 100755 --- a/module/blog/view/config/config.php +++ b/module/blog/view/config/config.php @@ -47,6 +47,6 @@
Version n° - +
diff --git a/module/form/form.php b/module/form/form.php index a47a0ec7..fd66b16a 100755 --- a/module/form/form.php +++ b/module/form/form.php @@ -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'; diff --git a/module/form/view/config/config.php b/module/form/view/config/config.php index 5d2e8946..fea6d9ff 100755 --- a/module/form/view/config/config.php +++ b/module/form/view/config/config.php @@ -164,5 +164,5 @@
Version n° - +
diff --git a/module/form/view/data/data.php b/module/form/view/data/data.php index c60511b4..947e20db 100755 --- a/module/form/view/data/data.php +++ b/module/form/view/data/data.php @@ -26,5 +26,5 @@
Version n° - +
\ No newline at end of file diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 77d0f2c3..e8526b7c 100755 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -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 = []; diff --git a/module/gallery/view/config/config.php b/module/gallery/view/config/config.php index 0c41378b..91400a98 100755 --- a/module/gallery/view/config/config.php +++ b/module/gallery/view/config/config.php @@ -58,6 +58,6 @@
Version n° - +
diff --git a/module/gallery/view/edit/edit.php b/module/gallery/view/edit/edit.php index 9b243d32..c745d1e5 100755 --- a/module/gallery/view/edit/edit.php +++ b/module/gallery/view/edit/edit.php @@ -64,6 +64,6 @@
Version n° - +
diff --git a/module/gallery/view/theme/theme.php b/module/gallery/view/theme/theme.php index 8ada32ed..694ecaf9 100755 --- a/module/gallery/view/theme/theme.php +++ b/module/gallery/view/theme/theme.php @@ -139,7 +139,7 @@
Version n° - +
\ No newline at end of file diff --git a/module/news/news.php b/module/news/news.php index 13fcb2fa..d65c2860 100755 --- a/module/news/news.php +++ b/module/news/news.php @@ -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 */ diff --git a/module/news/view/config/config.php b/module/news/view/config/config.php index f25fe3d0..73929b9d 100755 --- a/module/news/view/config/config.php +++ b/module/news/view/config/config.php @@ -48,5 +48,5 @@
Version n° - +
\ No newline at end of file diff --git a/module/redirection/redirection.php b/module/redirection/redirection.php index 5c92521c..97a5e6ea 100755 --- a/module/redirection/redirection.php +++ b/module/redirection/redirection.php @@ -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 diff --git a/module/redirection/view/config/config.php b/module/redirection/view/config/config.php index 72071f4c..ff421b39 100755 --- a/module/redirection/view/config/config.php +++ b/module/redirection/view/config/config.php @@ -37,5 +37,5 @@
Version n° - +
\ No newline at end of file diff --git a/module/search/search.php b/module/search/search.php index f84dfdeb..7952edd8 100755 --- a/module/search/search.php +++ b/module/search/search.php @@ -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() { diff --git a/module/search/view/config/config.php b/module/search/view/config/config.php index 37a60653..f54674d7 100755 --- a/module/search/view/config/config.php +++ b/module/search/view/config/config.php @@ -68,5 +68,5 @@
Version n° - +
\ No newline at end of file