forked from ZwiiCMS-Team/ZwiiCMS
getModules
This commit is contained in:
parent
fed10aa71d
commit
696d38b1f4
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
class helper {
|
||||
|
||||
/** Statut de la réécriture d'URL (pour éviter de lire le contenu du fichier .htaccess à chaque self::baseUrl()) */
|
||||
@ -19,7 +20,7 @@ class helper {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Récupérer l'adresse IP sans tenit compte du proxy
|
||||
* @return string IP adress
|
||||
* Cette focntion est utilisé par user
|
||||
@ -129,41 +130,52 @@ class helper {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* Retourne la liste des modules installés dans un tableau composé
|
||||
* du nom réel
|
||||
* du numéro de version
|
||||
*/
|
||||
public static function getModules($folder = 'module') {
|
||||
$modules = array();
|
||||
// Le dossier existe-t-il ?
|
||||
if (is_dir($folder)) {
|
||||
$dirs = array_diff(scandir($folder), array('..', '.'));
|
||||
foreach ($dirs as $key => $value) {
|
||||
// Dossier non vide
|
||||
if (file_exists($folder . '/' . $value . '/' . $value . '.php')) {
|
||||
// Lire les constantes en gérant les erreurs de nom de classe
|
||||
try {
|
||||
// Chargement des classes externes
|
||||
if ($folder !== 'module') {
|
||||
include_once ($folder . '/' . $value . '/' . $value . '.php');
|
||||
if ( class_exists($value) ) {
|
||||
$e = new $value;
|
||||
}
|
||||
}
|
||||
$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
|
||||
];
|
||||
|
||||
$dirs = array_diff(scandir($folder), array('..', '.'));
|
||||
foreach ($dirs as $key => $value) {
|
||||
// Dossier non vide
|
||||
if (file_exists($folder . '/' . $value . '/' . $value . '.php')) {
|
||||
// Lire les constantes
|
||||
try {
|
||||
$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);
|
||||
} catch (Exception $e){
|
||||
// on ne fait rien
|
||||
}
|
||||
// Constante VERSION
|
||||
if (array_key_exists('VERSION', $class_constants)) {
|
||||
$version = $value::VERSION;
|
||||
} else {
|
||||
$version = '0.0';
|
||||
}
|
||||
// Affection
|
||||
$modules [$value] = [
|
||||
'realName' => $realName,
|
||||
'version' => $version
|
||||
];
|
||||
} catch (Exception $e){
|
||||
// on ne fait rien
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return($modules);
|
||||
|
@ -44,7 +44,7 @@ class common {
|
||||
const ACCESS_TIMER = 1800;
|
||||
|
||||
// Numéro de version
|
||||
const ZWII_VERSION = '10.4.02.modules';
|
||||
const ZWII_VERSION = '10.5.00';
|
||||
const ZWII_UPDATE_CHANNEL = "v10";
|
||||
|
||||
public static $actions = [];
|
||||
|
@ -34,7 +34,7 @@ class config extends common {
|
||||
'moduleDelete' => self::GROUP_ADMIN
|
||||
|
||||
];
|
||||
|
||||
|
||||
public static $modInstal = [];
|
||||
public static $str;
|
||||
|
||||
@ -597,13 +597,13 @@ class config extends common {
|
||||
'view' => 'advanced'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Installation de modules à partir d'un zip normalisé
|
||||
* Affichage des modules installés
|
||||
*/
|
||||
public function modules() {
|
||||
|
||||
var_dump(helper::getModules ());
|
||||
// Préparation du tableau des modules installés
|
||||
// Liste des modules installés (répertoire de module/)
|
||||
if ($dh = opendir( 'module/' )) {
|
||||
@ -611,11 +611,11 @@ class config extends common {
|
||||
while (($dirmodule = readdir($dh)) !== false) {
|
||||
if( $dirmodule !== '.' && $dirmodule !== '..'){
|
||||
self::$modInstal[$i][0] = $dirmodule;
|
||||
self::$modInstal[$i][1] = page::$moduleNames[$dirmodule];
|
||||
self::$modInstal[$i][1] = page::$moduleNames[$dirmodule];
|
||||
// Lecture de la version pour les modules officiels et distribués
|
||||
$blogversion = blog::VERSION;
|
||||
$formversion = form::VERSION;
|
||||
$galleryversion = gallery::VERSION;
|
||||
$galleryversion = gallery::VERSION;
|
||||
$newsversion = news::VERSION;
|
||||
$redirectionversion = redirection::VERSION;
|
||||
$searchversion = search::VERSION;
|
||||
@ -627,7 +627,7 @@ class config extends common {
|
||||
// Lecture de la version pour les modules non distribués
|
||||
elseif($this->getData(['module', '_gestion_modules_' , $dirmodule, 'version' ]) !== null){
|
||||
self::$modInstal[$i][2] = $this->getData(['module', '_gestion_modules_' , $dirmodule, 'version' ]);
|
||||
}
|
||||
}
|
||||
self::$modInstal[$i][3] = 'non';
|
||||
self::$modInstal[$i][4] = '';
|
||||
self::$modInstal[$i][5] = '';
|
||||
@ -652,16 +652,16 @@ class config extends common {
|
||||
}
|
||||
$modulesDistrib = array('blog', 'form', 'gallery', 'news', 'redirection', 'search');
|
||||
if( self::$modInstal[$i][4] =='' && array_search( self::$modInstal[$i][0], $modulesDistrib ) === false
|
||||
&& $this->getData(['module', '_gestion_modules_', self::$modInstal[$i][0], 'delete' ]) === true){
|
||||
&& $this->getData(['module', '_gestion_modules_', self::$modInstal[$i][0], 'delete' ]) === true){
|
||||
self::$modInstal[$i][5] = template::button('moduleDelete' . self::$modInstal[$i][0], [
|
||||
'class' => 'moduleDelete buttonRed',
|
||||
'href' => helper::baseUrl() . $this->getUrl(0) . '/moduleDelete/' . self::$modInstal[$i][0] . '/' . $_SESSION['csrf'],
|
||||
'value' => template::ico('cancel')
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Retour du formulaire ?
|
||||
if($this->isPost()) {
|
||||
// Installation d'un module
|
||||
@ -681,7 +681,7 @@ class config extends common {
|
||||
$moduleDir = self::TEMP_DIR . $tempFolder . '/module';
|
||||
$moduleName = '';
|
||||
if ( is_dir( $moduleDir )) {
|
||||
// Lire le nom du module
|
||||
// Lire le nom du module
|
||||
if ($dh = opendir( $moduleDir )) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$moduleName = $file;
|
||||
@ -690,7 +690,7 @@ class config extends common {
|
||||
}
|
||||
// Module normalisé ?
|
||||
if( is_file( $moduleDir.'/'.$moduleName.'/'.$moduleName.'.php' ) AND is_file( $moduleDir.'/'.$moduleName.'/view/index/index.php' ) ){
|
||||
|
||||
|
||||
// Lecture de info.json et mémorisation des 3 paramètres version, update et delete
|
||||
$version = '?';
|
||||
$update = '?';
|
||||
@ -707,7 +707,7 @@ class config extends common {
|
||||
$this->setData(['module','_gestion_modules_',$moduleName, 'version', $version]);
|
||||
$this->setData(['module','_gestion_modules_',$moduleName, 'update', $update]);
|
||||
$this->setData(['module','_gestion_modules_',$moduleName, 'delete', $delete]);
|
||||
|
||||
|
||||
// Module déjà installé ?
|
||||
$moduleInstal = false;
|
||||
foreach( self::$modInstal as $key=>$value){
|
||||
@ -725,7 +725,7 @@ class config extends common {
|
||||
if(is_bool($update)){
|
||||
$validMaj = $checkValidMaj && $update;
|
||||
}
|
||||
|
||||
|
||||
// Nouvelle installation ou mise à jour du module avec validation du concepteur et validation de l'utilisateur
|
||||
if( ! $moduleInstal || ( $moduleInstal && $validMaj )){
|
||||
// Copie récursive des dossiers
|
||||
@ -756,7 +756,7 @@ class config extends common {
|
||||
$notification = 'Impossible d\'ouvrir l\'archive';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->addOutput([
|
||||
'redirect' => helper::baseUrl() . $this->getUrl(),
|
||||
'notification' => $notification,
|
||||
@ -769,13 +769,13 @@ class config extends common {
|
||||
'view' => 'modules'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Effacement d'un module installé et non utilisé
|
||||
*/
|
||||
public function moduleDelete() {
|
||||
|
||||
|
||||
// Jeton incorrect
|
||||
if ($this->getUrl(3) !== $_SESSION['csrf']) {
|
||||
// Valeurs en sortie
|
||||
@ -805,8 +805,8 @@ class config extends common {
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function script() {
|
||||
// Soumission du formulaire
|
||||
if($this->isPost()) {
|
||||
@ -1027,31 +1027,31 @@ class config extends common {
|
||||
}
|
||||
return $newArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Copie récursive de dossiers
|
||||
* Copie récursive de dossiers
|
||||
*
|
||||
*/
|
||||
private function custom_copy($src, $dst) {
|
||||
// open the source directory
|
||||
$dir = opendir($src);
|
||||
// Make the destination directory if not exist
|
||||
@mkdir($dst);
|
||||
// Loop through the files in source directory
|
||||
while( $file = readdir($dir) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ){
|
||||
// Recursively calling custom copy function
|
||||
// for sub directory
|
||||
$this -> custom_copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
private function custom_copy($src, $dst) {
|
||||
// open the source directory
|
||||
$dir = opendir($src);
|
||||
// Make the destination directory if not exist
|
||||
@mkdir($dst);
|
||||
// Loop through the files in source directory
|
||||
while( $file = readdir($dir) ) {
|
||||
if (( $file != '.' ) && ( $file != '..' )) {
|
||||
if ( is_dir($src . '/' . $file) ){
|
||||
// Recursively calling custom copy function
|
||||
// for sub directory
|
||||
$this -> custom_copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
else {
|
||||
copy($src . '/' . $file, $dst . '/' . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1086,6 +1086,6 @@ class config extends common {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -440,9 +440,8 @@ class page extends common {
|
||||
'state' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
self::$moduleIds = array_merge( ['' => 'Aucun'] , helper::arrayCollumn(helper::getModules(),'realName','SORT_ASC'));
|
||||
// Pages sans parent
|
||||
}
|
||||
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)) {
|
||||
self::$pagesNoParentId[$parentPageId] = $this->getData(['page', $parentPageId, 'title']);
|
||||
|
Loading…
Reference in New Issue
Block a user