2016-11-17 22:16:26 +01:00
< ? php
2010-10-05 17:30:04 +02:00
function __autoload ( $class )
{
2016-11-17 22:16:26 +01:00
$BASE_DIR = $_SERVER [ 'DOCUMENT_ROOT' ] . '/accueil/' ; // à modifier selon la configuration souhaitée
set_include_path ( $BASE_DIR );
$path = 'modules/' . $class ;
if ( file_exists ( $path . DIRECTORY_SEPARATOR . ucfirst ( $class ) . '.php' ) || file_exists ( $BASE_DIR . $path . DIRECTORY_SEPARATOR . ucfirst ( $class ) . '.php' )) {
require_once ( $path . DIRECTORY_SEPARATOR . ucfirst ( $class ) . '.php' );
} else {
require_once ( 'class/' . $class . '.php' );
}
2010-10-05 17:30:04 +02:00
}
2016-11-17 22:16:26 +01:00
class AccueilModules
{
const CONFIG_FILE = 'db/config.xml' ;
private $modules = array ();
/**
* Constructeur
* Initialise le XML de conf générale
*/
function __construct ()
{
if ( $config = simplexml_load_file ( self :: CONFIG_FILE )) {
$config_xml = $config -> item ;
foreach ( $config_xml as $item ) {
$this -> modules [ " $item[id] " ] = $item ;
}
} else {
echo 'Impossible de trouver le fichier de configuration.' ;
}
}
/**
*
* Initialise les modules activés uniquement
*/
function getModules ()
{
foreach ( $this -> modules as $module => $moduleConf ) {
if ( file_exists ( 'modules/' . $module . '/' . ucfirst ( $module ) . '.php' ) && $moduleConf -> visibility == " true " ) {
$params = array ();
foreach ( $moduleConf as $confParam ) {
$params [ $confParam -> getName ()] = " $confParam " ;
}
$module = new $module ( $params );
if ( is_subclass_of ( $module , 'Module' )) {
$module -> build ();
}
// require 'modules/'.$module.'/'.ucfirst($module).'.php';
// call_user_func(array($module, "start"), $module, $params);
}
}
}
2010-10-05 17:30:04 +02:00
2016-11-17 22:16:26 +01:00
/**
*
* @ return le module donné avec ses paramètres actuellement présent en conf
*/
public static function getModule ( $module )
{
2016-11-21 23:03:59 +01:00
if ( $config = simplexml_load_file ( __DIR__ . '/../' . self :: CONFIG_FILE )) {
foreach ( $config -> item as $item ) {
$item_id = ( string ) $item [ 'id' ];
if ( $item_id == $module ) {
2016-11-17 22:16:26 +01:00
$params = array ();
foreach ( $item as $confParam ) {
$params [ $confParam -> getName ()] = " $confParam " ;
}
//require '../modules/'.$module.'/'.ucfirst($module).'.php';
return new $module ( $params );
}
}
echo " object not found " ;
return ;
} else {
echo " bad persistance " ;
return ;
}
2010-09-15 16:55:54 +02:00
2016-11-17 22:16:26 +01:00
}
/**
*
* Construit et insère le menu de changement de config
*/
function buildConfigMenu ()
{
echo ' < a href = " #config " id = " config-menu " >< img src = " images/interface/config.png " /></ a >
2010-09-15 16:55:54 +02:00
< div style = " display:none; " >
< div id = " config " >
< form id = " config_form " action = " " method = " post " >
< h3 > Modules configuration </ h3 >< br /> ' ;
2016-11-17 22:16:26 +01:00
foreach ( $this -> modules as $module => $moduleConf ) {
echo $module . ' module : <input type="radio" name="' . $module . '_group" value="true"' ;
if ( $moduleConf -> visibility == " true " ) echo " checked " ;
echo '/>activé <input type="radio" name="' . $module . '_group" value="false"' ;
if ( $moduleConf -> visibility == " false " ) echo " checked " ;
echo '/>desactivé<br/><br/>' ;
}
echo ' < span id = " config-submit " class = " green-button " > Enregistrer </ span >
2010-09-27 16:37:14 +02:00
</ form >< br />< br />
< h3 > Ajout d\ ' un module </ h3 >
< form action = " includes/addModule.php " method = " POST " enctype = " multipart/form-data " >
< input type = " file " name = " newModuleFile " id = " newModuleFile " />
< input type = " submit " value = " Envoyer " />
2010-09-15 16:55:54 +02:00
</ form >
</ div >
</ div > ' ;
2016-11-17 22:16:26 +01:00
echo ' < script > $ ( document ) . ready ( function (){
2010-09-17 15:38:57 +02:00
$ ( \ ' #config-submit\').live(\'click\',function(e){
$ ( this ) . replaceWith ( \ ' < img src = " images/interface/ajax_load.gif " style = " margin:30px auto;display:block " /> \ ' );
var data3 = { ' ;
2016-11-17 22:16:26 +01:00
$temp = '' ;
foreach ( $this -> modules as $module => $moduleConf ) {
$temp .= '\'' . $module . '\' : $(\'input[type=radio][name=' . $module . '_group]:checked\').attr(\'value\'),' ;
}
echo substr ( $temp , 0 , - 1 );
echo ' };
2010-09-17 15:38:57 +02:00
$ . post ( \ ' ajax / post - config . php\ ' , data3 , function ( msg3 ){
2010-09-22 16:02:40 +02:00
location . reload ();
2010-09-17 15:38:57 +02:00
});
e . preventDefault ();
});
});
</ script > ' ;
2016-11-17 22:16:26 +01:00
}
public static function retrieveModuleParams ( $module )
{
$temp = new $module ;
return $temp -> getParamsList ();
}
/**
*
* Fonction d ' ajout de module dans le fichier de config
*/
public static function addModule ( $file , $name )
{
if ( $config = simplexml_load_file ( '../' . self :: CONFIG_FILE )) {
foreach ( $config -> item as $item ) {
if ( $item [ 'id' ] == $name )
exit ( 'module déjà présent !' );
}
}
if ( class_exists ( 'ZipArchive' )) {
$zip = new ZipArchive ;
$res = $zip -> open ( $file );
if ( $res === TRUE ) {
$zip -> extractTo ( '../modules/' );
$zip -> close ();
if ( ! file_exists ( '../modules/' . $name . '/' . ucfirst ( $name ) . '.php' ))
exit ( 'L\'extraction n\'a pas fonctionné...' );
else {
unlink ( $file );
require '../modules/' . $name . '/' . ucfirst ( $name ) . '.php' ;
if ( $config = simplexml_load_file ( '../' . self :: CONFIG_FILE )) {
$newItem = $config -> addChild ( 'item' );
$newItem -> addAttribute ( 'id' , $name );
//$params = call_user_func(array($name, 'getParamList'));
$params = self :: retrieveModuleParams ( $name );
foreach ( $params as $param ) {
if ( $param == 'visibility' )
$newItem -> AddChild ( $param , 'true' );
else
$newItem -> AddChild ( $param , '0' );
}
$config -> asXML ( '../' . self :: CONFIG_FILE );
echo 'Module enregistré. Vous pouvez revenir à la page d\'accueil' ;
} else {
exit ( 'L\'enregistrement dans le menu a échoué...' );
}
}
} else {
exit ( 'failed, code:' . $res );
}
} else {
exit ( 'Votre serveur ne peut installer les modules automatiquement. Merci de passer par votre client FTP habituel ou d\'ajouter la classe ZipArchive à votre serveur PHP' );
}
}
2010-09-15 16:55:54 +02:00
}