Ajout de la fonctionnalité d'upload de module.

This commit is contained in:
Chouchen 2010-09-27 14:37:14 +00:00
parent 734e6f4829
commit 5a8dbbb330
12 changed files with 78 additions and 138 deletions

View File

@ -1,10 +0,0 @@
<?php
// Error reporting
error_reporting(E_ALL^E_NOTICE);
// Escaping:
$city = $_GET['city'];
include '../class/AccueilModules.php';
echo AccueilModules::updateModule('weather', array('city'=>$city));
?>

View File

@ -1,4 +1,4 @@
<?php
<?php
require 'Module.php';
class AccueilModules {
const CONFIG_FILE = 'db/config.xml';
@ -6,7 +6,7 @@ class AccueilModules {
/**
* Constructeur
* Initialise le XML de conf générale
* Initialise le XML de conf générale
* Active les modules
* Construit le menu
*/
@ -25,7 +25,7 @@ class AccueilModules {
/**
*
* Initialise les modules activés uniquement
* Initialise les modules activés uniquement
*/
function getModules(){
foreach($this->modules as $module=>$moduleConf){
@ -42,7 +42,7 @@ class AccueilModules {
/**
*
* Construit et insère le menu de changement de config
* 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>
@ -53,11 +53,16 @@ class AccueilModules {
foreach($this->modules as $module=>$moduleConf){
echo $module.' module : <input type="radio" name="'.$module.'_group" value="true"';
if ($moduleConf->visibility == "true") echo " checked";
echo '/>true&nbsp;&nbsp;<input type="radio" name="'.$module.'_group" value="false"';
echo '/>activé&nbsp;&nbsp;<input type="radio" name="'.$module.'_group" value="false"';
if ($moduleConf->visibility == "false") echo " checked";
echo '/>false<br/><br/>';
echo '/>desactivé<br/><br/>';
}
echo '<span id="config-submit" class="green-button">Enregistrer</span>
</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"/>
</form>
</div>
</div>';
@ -82,13 +87,60 @@ class AccueilModules {
/**
*
* @property Chaque module possède la fonction updateModule en static qui permet de changer un ou plusieurs de ses attributs
* @param $module String Nom du module à modifier
* @param $things2change Array du ou des attributs à modifier avec sa ou ses nouvelles valeurs
* @property Chaque module possède la fonction updateModule en static qui permet de changer un ou plusieurs de ses attributs
* @param $module String Nom du module à modifier
* @param $things2change Array du ou des attributs à modifier avec sa ou ses nouvelles valeurs
* @return "ok" String si c'est bon, ou le message d'erreur
*/
public static function updateModule($module, $things2change){
require '../modules/'.$module.'/'.ucfirst($module).'.php';
return call_user_func(array($module, "updateConfig"), $things2change);
}
/**
*
* 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'));
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');
}
}
}

View File

@ -1,12 +0,0 @@
<div id="config">
<form id="config_form" action="" method="post">
<h3>Modules configuration</h3><br/>
Clock module : <input type="radio" name="clock_group" value="true"<?if ($config_xml[0]->visibility == "true"){echo " checked";}?> />true&nbsp;&nbsp;<input type="radio" name="clock_group" value="false"<?if ($config_xml[0]->visibility == "false"){echo " checked";}?> />false<br/><br/>
Meteo module : <input type="radio" name="meteo_group" value="true"<?if ($config_xml[1]->visibility == "true"){echo " checked";}?> />true&nbsp;&nbsp;<input type="radio" name="meteo_group" value="false"<?if ($config_xml[1]->visibility == "false"){echo " checked";}?> />false<br/><br/>
Notes module : <input type="radio" name="notes_group" value="true"<?if ($config_xml[2]->visibility == "true"){echo " checked";}?> />true&nbsp;&nbsp;<input type="radio" name="notes_group" value="false"<?if ($config_xml[2]->visibility == "false"){echo " checked";}?> />false<br/><br/>
Search module : <input type="radio" name="search_group" value="true"<?if ($config_xml[3]->visibility == "true"){echo " checked";}?> />true&nbsp;&nbsp;<input type="radio" name="search_group" value="false"<?if ($config_xml[3]->visibility == "false"){echo " checked";}?> />false<br/><br/>
Links module : <input type="radio" name="links_group" value="true"<?if ($config_xml[4]->visibility == "true"){echo " checked";}?> />true&nbsp;&nbsp;<input type="radio" name="links_group" value="false"<?if ($config_xml[4]->visibility == "false"){echo " checked";}?> />false<br/><br/>
Blogs module : <input type="radio" name="blogs_group" value="true"<?if ($config_xml[5]->visibility == "true"){echo " checked";}?> />true&nbsp;&nbsp;<input type="radio" name="blogs_group" value="false"<?if ($config_xml[5]->visibility == "false"){echo " checked";}?> />false<br/><br/>
<a id="config-submit" href="" class="green-button">Enregistrer</a>
</form>
</div>

1
includes/addModule.php Normal file
View File

@ -0,0 +1 @@
<?php $newModuleFile = $_FILES['newModuleFile']; // Préparation de l'image2 $content_dir = '../'; // dossier où sera déplacé le fichier $tmp_file = $newModuleFile['tmp_name']; // Fichier temporaire // Vérification de l'upload if( !is_uploaded_file($tmp_file) ) { exit("Le fichier est introuvable"); } // on vérifie maintenant l'extension // $type_file = $newModuleFile['type']; $extension = substr($newModuleFile['name'], strlen($newModuleFile['name'])-3, 3); if($extension != 'zip') //if( !strstr($type_file, 'zip')) { exit("Le fichier n'est pas une archive valide : ".$extension); } // on copie le fichier dans le dossier de destination $name_file = $newModuleFile['name']; if( preg_match('#[\x00-\x1F\x7F-\x9F/\\\\]#', $name_file) ) { exit("Nom de fichier non valide : ".$name_file); } else if( !move_uploaded_file($tmp_file, $content_dir . $name_file) ) { exit("Impossible de copier le fichier dans $content_dir"); } require '../class/AccueilModules.php'; echo AccueilModules::addModule($content_dir.$name_file, strtolower(substr($name_file,0, -4)));

View File

@ -47,18 +47,6 @@ class links extends Module{
$links = new links($params);
}
public function setLink($link){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.self::LINKS_FILE);
$path = $xmla->xpath("//item[@id='weather']");
$path[0]->x = $x;
$xmla->asXML('../'.AccueilModules::CONFIG_FILE);
echo "ok";
}
public function setVisibility($visibility){
// Saving the position and z-index of the note:
$xmla = simplexml_load_file('../'.AccueilModules::CONFIG_FILE);

View File

@ -14,8 +14,8 @@ class search extends Module {
$this->moduleName = get_class();
$this->pathToModule = 'modules/'.$this->moduleName.'/';
$this->setParams($params);
echo '<link rel="stylesheet" type="text/css" href="'.$this->pathToModule.'css/search.css">
<script type="text/javascript" src="'.$this->pathToModule.'js/jquery.search.js"></script>
echo '<link rel="stylesheet" type="text/css" href="'.$this->pathToModule.'css/'.$this->moduleName.'.css">
<script type="text/javascript" src="'.$this->pathToModule.'js/'.$this->moduleName.'.js"></script>
<form id="searchForm" method="post">
<fieldset>
<input id="s" type="text" />

View File

@ -1,18 +1,3 @@
<?
$xmla = simplexml_load_file('../db/todoist.xml');
if($xmla->token== '' || $xmla->token == null)
header('Location: install-todoist.php');
if($xmla->name == '' || $xmla->name == null):?>
<html>
<head> <style> .selectableProject{text-decoration:underline; color:blue; cursor:pointer;} </style>
<title>Todoist : getProjects</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="../js/getProjectsList.php?token=<?=$xmla->token?>"></script>
</head>
<body>
</body>
</html>
<? else:
header('Location: index.php');
endif;
<? $xmla = simplexml_load_file('../db/todoist.xml'); if($xmla->token== '' || $xmla->token == null) header('Location: install-todoist.php'); if($xmla->name == '' || $xmla->name == null):?> <html> <head> <style> .selectableProject{text-decoration:underline; color:blue; cursor:pointer;} </style>
<title>Todoist : getProjects</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="../js/getProjectsList.php?token=<?=$xmla->token?>"></script> </head> <body>
</body> </html> <? else: header('Location: ../../../'); endif;

View File

@ -1,7 +1,7 @@
<?
$xmla = simplexml_load_file('../db/todoist.xml');
if($xmla->token== '' || $xmla->token == null)
header('Location: ./');
header('Location: install-todoist.php');
if($xmla->id != '' || $xmla->id != null):
$token = $xmla->token;
$id = $xmla->id;?>

View File

@ -1,56 +1,9 @@
<?header('Content-type: application/javascript'); $token = $_GET['token']; $id = $_GET['id']; ?>
function cbfunc(o){
$('#results').append('<ul id="uncompletedList"><ul>');
for(var i in o)
{
$('#uncompletedList').append('<li id="'+o[i].id+'">'+o[i].content+' - '+o[i].date_string+' <img src="images/interface/delete.png" class="deleteTask" id="delete-'+o[i].id+'"/> <img src="images/interface/complete.png" class="completeTask" id="complete-'+o[i].id+'"/> </li>');
} $('#uncompletedList li').prepend('<div class="puce"></div>');
}
function cbfunc2(o){
$('#uncompletedList').append('<li id="'+o.id+'">'+o.content+' - '+o.date_string+' <img src="images/interface/delete.png" id="delete-'+o.id+'"/> <img src="images/interface/complete.png" class="completeTask" id="complete-'+o.id+'"/> </li>');
}
$(document).ready(function(){ $('#todo').resizable(); $('#todo').draggable(); $('#todo').append('<div id="results"></div><img src="images/interface/add.png" id="showNewTask"/><fieldset id="newTaskFieldset" style="display:none; width:200px;"><input type="text" name="newtask" id="newtask"/> <select id="priority"><option id="1" value="1">1</option><option id="2" value="2">2</option><option id="3" value="3">3</option><option id="4" value="4">4</option></select> <br/><input type="text" name="date_string" id="date_string"/> <img src="images/interface/add.png" id="addTask"/></fieldset>');
var token = "<?=$token?>";
var project_id = "<?=$id?>";
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/getUncompletedItems?project_id='+project_id+'&token='+token+'&format=json&callback=cbfunc';
document.getElementsByTagName('head')[0].appendChild(script);
$('#showNewTask').click(function(){
$('#newTaskFieldset').toggle();
});
$('#addTask').click(function(){
var content = $('#newtask').val();
var date_string = $('#date_string').val();
var priority = $('#priority').val();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/addItem?project_id='+project_id+'&token='+token+'&content='+content+'&date_string='+date_string+'&priority='+priority+'&format=json&callback=cbfunc2';
document.getElementsByTagName('head')[0].appendChild(script);
});
$('.deleteTask').live('click', function(){
var id = $(this).attr('id');
arrayId = id.split('-');
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/deleteItems?ids=["'+arrayId[1]+'"]&token='+token;
document.getElementsByTagName('head')[0].appendChild(script);
$('#'+arrayId[1]).remove();
});
$('.completeTask').live('click', function(){
var id = $(this).attr('id');
arrayId = id.split('-');
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/completeItems?ids=["'+arrayId[1]+'"]&token='+token;
document.getElementsByTagName('head')[0].appendChild(script);
$('#'+arrayId[1]).remove();
});
/* A helper function for converting a set of elements to draggables: */ make_draggable($('#todo'));
function cbfunc(o){ $('#results').append('<ul id="uncompletedList"><ul>'); for(var i in o) { $('#uncompletedList').append('<li id="'+o[i].id+'">'+o[i].content+' - '+o[i].date_string+' <img src="images/interface/delete.png" class="deleteTask" id="delete-'+o[i].id+'"/> <img src="images/interface/complete.png" class="completeTask" id="complete-'+o[i].id+'"/> </li>'); } $('#uncompletedList li').prepend('<div class="puce"></div>'); }
function cbfunc2(o){ $('#uncompletedList').append('<li id="'+o.id+'">'+o.content+' - '+o.date_string+' <img src="images/interface/delete.png" id="delete-'+o.id+'"/> <img src="images/interface/complete.png" class="completeTask" id="complete-'+o.id+'"/> </li>'); }
$(document).ready(function(){ $('#todo').resizable(); $('#todo').draggable(); $('#todo').append('<div id="results"></div><img src="images/interface/add.png" id="showNewTask"/><fieldset id="newTaskFieldset" style="display:none; width:200px;"><input type="text" name="newtask" id="newtask"/> <select id="priority"><option id="1" value="1">1</option><option id="2" value="2">2</option><option id="3" value="3">3</option><option id="4" value="4">4</option></select> <br/><input type="text" name="date_string" id="date_string"/> <img src="images/interface/add.png" id="addTask"/></fieldset>'); var token = "<?=$token?>"; var project_id = "<?=$id?>"; var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/getUncompletedItems?project_id='+project_id+'&token='+token+'&format=json&callback=cbfunc'; document.getElementsByTagName('head')[0].appendChild(script);
$('#showNewTask').click(function(){ $('#newTaskFieldset').toggle(); });
$('#addTask').click(function(){ var content = $('#newtask').val(); var date_string = $('#date_string').val(); var priority = $('#priority').val(); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/addItem?project_id='+project_id+'&token='+token+'&content='+content+'&date_string='+date_string+'&priority='+priority+'&format=json&callback=cbfunc2'; document.getElementsByTagName('head')[0].appendChild(script); });
$('.deleteTask').live('click', function(){ var id = $(this).attr('id'); arrayId = id.split('-'); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/deleteItems?ids=["'+arrayId[1]+'"]&token='+token; document.getElementsByTagName('head')[0].appendChild(script); $('#'+arrayId[1]).remove(); }); $('.completeTask').live('click', function(){ var id = $(this).attr('id'); arrayId = id.split('-'); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/completeItems?ids=["'+arrayId[1]+'"]&token='+token; document.getElementsByTagName('head')[0].appendChild(script); $('#'+arrayId[1]).remove(); });
/* A helper function for converting a set of elements to draggables: */ make_draggable($('#todo'));
});

View File

@ -1,21 +1,4 @@
function cbfunc(o){
var token = o.api_token;
if(token == undefined){
$('#error').html('Identification erronnée');
}else{
$.post('../ajax/saveTodoist.php', {token: token}, function(data){ $('body').append('<a href="getProjectsList.php">Etape suivante</a>'); if(data=="ok"){
function cbfunc(o){ var token = o.api_token; if(token == undefined){ $('#error').html('Identification erronnée'); }else{ $.post('../ajax/saveTodoist.php', {token: token}, function(data){ $('body').append('<a href="getProjectsList.php">Etape suivante</a>'); if(data=="ok"){
location.reload(); }else{ alert(data); }
});
}
}
$(document).ready(function(){
$('#loginBtn').click(function(){
var email = $('#email').val();
var password = $('#password').val();
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://todoist.com/API/login?email='+email+'&password='+password+'&format=json&callback=cbfunc';
document.getElementsByTagName('head')[0].appendChild(script);
});
});
}); } }
$(document).ready(function(){ $('#loginBtn').click(function(){ var email = $('#email').val(); var password = $('#password').val(); var script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'https://todoist.com/API/login?email='+email+'&password='+password+'&format=json&callback=cbfunc'; document.getElementsByTagName('head')[0].appendChild(script); }); $('#email').keydown(function(e){ if(e.which == 13){ $('#loginBtn').trigger('click'); } }); $('#password').keydown(function(e){ if(e.which == 13){ $('#loginBtn').trigger('click'); } }); });