From 5a8dbbb3304b2b63f215e6b3cfc360cb085673e4 Mon Sep 17 00:00:00 2001 From: Chouchen Date: Mon, 27 Sep 2010 14:37:14 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20fonctionnalit=C3=A9=20d'uploa?= =?UTF-8?q?d=20de=20module.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ajax/update-city.php | 10 --- class/AccueilModules.php | 70 ++++++++++++++++--- config.php | 12 ---- includes/addModule.php | 1 + modules/links/Links.php | 12 ---- {ajax => modules/notes/ajax}/delete-notes.php | 0 {ajax => modules/notes/ajax}/post-notes.php | 0 modules/search/Search.php | 4 +- modules/todo/includes/getProjectsList.php | 21 +----- modules/todo/includes/getUncompletedTasks.php | 2 +- modules/todo/js/getUncompletedTasks.php | 61 ++-------------- modules/todo/js/index.js | 23 +----- 12 files changed, 78 insertions(+), 138 deletions(-) delete mode 100644 ajax/update-city.php delete mode 100644 config.php create mode 100644 includes/addModule.php rename {ajax => modules/notes/ajax}/delete-notes.php (100%) rename {ajax => modules/notes/ajax}/post-notes.php (100%) diff --git a/ajax/update-city.php b/ajax/update-city.php deleted file mode 100644 index 99ce595..0000000 --- a/ajax/update-city.php +++ /dev/null @@ -1,10 +0,0 @@ -$city)); - -?> \ No newline at end of file diff --git a/class/AccueilModules.php b/class/AccueilModules.php index 955d75f..ccd31d2 100644 --- a/class/AccueilModules.php +++ b/class/AccueilModules.php @@ -1,4 +1,4 @@ -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 ' @@ -53,11 +53,16 @@ class AccueilModules { foreach($this->modules as $module=>$moduleConf){ echo $module.' module : visibility == "true") echo " checked"; - echo '/>true  activé  visibility == "false") echo " checked"; - echo '/>false

'; + echo '/>desactivé

'; } echo 'Enregistrer +

+

Ajout d\'un module

+
+ +
'; @@ -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'); + } + } } \ No newline at end of file diff --git a/config.php b/config.php deleted file mode 100644 index aa54c3a..0000000 --- a/config.php +++ /dev/null @@ -1,12 +0,0 @@ -
-
-

Modules configuration


- Clock module : visibility == "true"){echo " checked";}?> />true  visibility == "false"){echo " checked";}?> />false

- Meteo module : visibility == "true"){echo " checked";}?> />true  visibility == "false"){echo " checked";}?> />false

- Notes module : visibility == "true"){echo " checked";}?> />true  visibility == "false"){echo " checked";}?> />false

- Search module : visibility == "true"){echo " checked";}?> />true  visibility == "false"){echo " checked";}?> />false

- Links module : visibility == "true"){echo " checked";}?> />true  visibility == "false"){echo " checked";}?> />false

- Blogs module : visibility == "true"){echo " checked";}?> />true  visibility == "false"){echo " checked";}?> />false

- Enregistrer -
-
\ No newline at end of file diff --git a/includes/addModule.php b/includes/addModule.php new file mode 100644 index 0000000..0de5283 --- /dev/null +++ b/includes/addModule.php @@ -0,0 +1 @@ +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); diff --git a/ajax/delete-notes.php b/modules/notes/ajax/delete-notes.php similarity index 100% rename from ajax/delete-notes.php rename to modules/notes/ajax/delete-notes.php diff --git a/ajax/post-notes.php b/modules/notes/ajax/post-notes.php similarity index 100% rename from ajax/post-notes.php rename to modules/notes/ajax/post-notes.php diff --git a/modules/search/Search.php b/modules/search/Search.php index e1c7b24..b4dd4a0 100644 --- a/modules/search/Search.php +++ b/modules/search/Search.php @@ -14,8 +14,8 @@ class search extends Module { $this->moduleName = get_class(); $this->pathToModule = 'modules/'.$this->moduleName.'/'; $this->setParams($params); - echo ' - + echo ' +
diff --git a/modules/todo/includes/getProjectsList.php b/modules/todo/includes/getProjectsList.php index ba97bba..c83ad06 100644 --- a/modules/todo/includes/getProjectsList.php +++ b/modules/todo/includes/getProjectsList.php @@ -1,18 +1,3 @@ -token== '' || $xmla->token == null) - header('Location: install-todoist.php'); -if($xmla->name == '' || $xmla->name == null):?> - - - Todoist : getProjects - - - - - - - - token== '' || $xmla->token == null) header('Location: install-todoist.php'); if($xmla->name == '' || $xmla->name == null):?> + Todoist : getProjects + token== '' || $xmla->token == null) - header('Location: ./'); + header('Location: install-todoist.php'); if($xmla->id != '' || $xmla->id != null): $token = $xmla->token; $id = $xmla->id;?> diff --git a/modules/todo/js/getUncompletedTasks.php b/modules/todo/js/getUncompletedTasks.php index 511f32b..32231bb 100644 --- a/modules/todo/js/getUncompletedTasks.php +++ b/modules/todo/js/getUncompletedTasks.php @@ -1,56 +1,9 @@ -function cbfunc(o){ - $('#results').append('
      '); - for(var i in o) - { - $('#uncompletedList').append('
    • '+o[i].content+' - '+o[i].date_string+'
    • '); - } $('#uncompletedList li').prepend('
      '); -} - -function cbfunc2(o){ - $('#uncompletedList').append('
    • '+o.content+' - '+o.date_string+'
    • '); -} - -$(document).ready(function(){ $('#todo').resizable(); $('#todo').draggable(); $('#todo').append('
      '); - var token = ""; - var project_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('
          '); for(var i in o) { $('#uncompletedList').append('
        • '+o[i].content+' - '+o[i].date_string+'
        • '); } $('#uncompletedList li').prepend('
          '); } +function cbfunc2(o){ $('#uncompletedList').append('
        • '+o.content+' - '+o.date_string+'
        • '); } +$(document).ready(function(){ $('#todo').resizable(); $('#todo').draggable(); $('#todo').append('
          '); var token = ""; var project_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')); }); \ No newline at end of file diff --git a/modules/todo/js/index.js b/modules/todo/js/index.js index 90b2de2..61618c9 100644 --- a/modules/todo/js/index.js +++ b/modules/todo/js/index.js @@ -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('Etape suivante'); 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('Etape suivante'); 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); - }); -}); \ No newline at end of file + }); } } +$(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'); } }); }); \ No newline at end of file