diff --git a/components/plugin_manager/class.plugin_manager.php b/components/plugin_manager/class.plugin_manager.php index b7efdaa..305962e 100644 --- a/components/plugin_manager/class.plugin_manager.php +++ b/components/plugin_manager/class.plugin_manager.php @@ -57,5 +57,65 @@ class Plugin_manager extends Common { // Response echo formatJSEND("success",null); } + + ////////////////////////////////////////////////////////////////// + // Update Plugin + ////////////////////////////////////////////////////////////////// + public function Update($name){ + if(file_exists(PLUGINS.'/'.$name.'/plugin.json')) { + $data = json_decode(file_get_contents(PLUGINS.'/'.$name.'/plugin.json'),true); + if(substr($data[0]['url'],-4) == '.git') { + $data[0]['url'] = substr($data[0]['url'],0,-4); + } + $data[0]['url'] .= '/archive/master.zip'; + file_put_contents(PLUGINS.'/'.$name.'.zip', fopen($data[0]['url'], 'r')); + + $zip = new ZipArchive; + $res = $zip->open(PLUGINS.'/'.$name.'.zip'); + // open downloaded archive + if ($res === TRUE) { + // extract archive + if($zip->extractTo(PLUGINS) === true) { + if(substr($name, -6) != "master") { + $this->cpy(PLUGINS.'/'.$name.'-master', PLUGINS.'/'.$name, array(".","..")); + } + + $zip->close(); + } else { + echo formatJSEND("error","Unable to open ".$name.".zip"); + } + } else { + echo formatJSEND("error","ZIP Extension not found"); + } + + unlink(PLUGINS.'/'.$name.'.zip'); + // Response + echo formatJSEND("success",null); + } else { + echo formatJSEND("error","Unable to find plugin ".$name); + } + } + + function cpy($source, $dest, $ign){ + if(is_dir($source)) { + $dir_handle=opendir($source); + while($file=readdir($dir_handle)){ + if(!in_array($file, $ign)){ + if(is_dir($source."/".$file)){ + mkdir($dest."/".$file); + cpy($source."/".$file, $dest."/".$file, $ign); + } else { + copy($source."/".$file, $dest."/".$file); + unlink($source."/".$file); + } + } + } + closedir($dir_handle); + rmdir($source); + } else { + copy($source, $dest); + unlink($source); + } + } } diff --git a/components/plugin_manager/controller.php b/components/plugin_manager/controller.php index 2f68f6b..20250a9 100644 --- a/components/plugin_manager/controller.php +++ b/components/plugin_manager/controller.php @@ -37,6 +37,15 @@ $Plugin_manager->Activate($_GET['name']); } } - + + ////////////////////////////////////////////////////////////////// + // Update Plugin + ////////////////////////////////////////////////////////////////// + + if($_GET['action']=='update'){ + if(checkAccess()) { + $Plugin_manager->Update($_GET['name']); + } + } ?> \ No newline at end of file diff --git a/components/plugin_manager/dialog.php b/components/plugin_manager/dialog.php index 11c7f2c..f8df5fe 100644 --- a/components/plugin_manager/dialog.php +++ b/components/plugin_manager/dialog.php @@ -87,7 +87,7 @@ ?> - +
@@ -105,7 +105,7 @@ Plugin Name Your Version Latest Version - Open + Update - +
@@ -163,7 +163,7 @@ ?>
- +
Downloading ' + name + '...

'); + $.get(_this.controller + '?action=update&name=' + name, function(data) { + var response = codiad.jsend.parse(data); + if (response == 'error') { + codiad.message.error(response.message); + } + _this.check(); + }); + }, ////////////////////////////////////////////////////////////////// // Activate Plugin @@ -52,8 +68,8 @@ activate: function(name) { var _this = this; $.get(this.controller + '?action=activate&name=' + name, function(data) { - var projectInfo = codiad.jsend.parse(data); - if (projectInfo != 'error') { + var response = codiad.jsend.parse(data); + if (response != 'error') { _this.list(); } }); @@ -66,8 +82,8 @@ deactivate: function(name) { var _this = this; $.get(this.controller + '?action=deactivate&name=' + name, function(data) { - var projectInfo = codiad.jsend.parse(data); - if (projectInfo != 'error') { + var response = codiad.jsend.parse(data); + if (response != 'error') { _this.list(); } });