From 3da2090e4bbfaeda0e66a69e83092a5705919404 Mon Sep 17 00:00:00 2001 From: daeks Date: Wed, 7 Aug 2013 17:36:21 +0200 Subject: [PATCH 1/3] first commit --- components/install/process.php | 7 +- components/market/class.market.php | 291 ++++++++++++++++ .../{theme_manager => market}/controller.php | 24 +- .../{plugin_manager => market}/dialog.php | 139 ++++---- components/{plugin_manager => market}/init.js | 48 +-- .../plugin_manager/class.plugin_manager.php | 200 ----------- components/plugin_manager/controller.php | 71 ---- components/right_bar.json | 11 +- .../theme_manager/class.theme_manager.php | 200 ----------- components/theme_manager/dialog.php | 313 ------------------ components/theme_manager/init.js | 134 -------- config.example.php | 7 +- plugins/README.md | 5 - themes/default/images/new.png | Bin 0 -> 2782 bytes 14 files changed, 401 insertions(+), 1049 deletions(-) create mode 100644 components/market/class.market.php rename components/{theme_manager => market}/controller.php (77%) rename components/{plugin_manager => market}/dialog.php (66%) rename components/{plugin_manager => market}/init.js (74%) delete mode 100644 components/plugin_manager/class.plugin_manager.php delete mode 100644 components/plugin_manager/controller.php delete mode 100644 components/theme_manager/class.theme_manager.php delete mode 100644 components/theme_manager/dialog.php delete mode 100644 components/theme_manager/init.js delete mode 100644 plugins/README.md create mode 100644 themes/default/images/new.png diff --git a/components/install/process.php b/components/install/process.php index 7164aa3..b5324fe 100644 --- a/components/install/process.php +++ b/components/install/process.php @@ -208,11 +208,8 @@ define("WORKSPACE", BASE_PATH . "/workspace"); // URLS define("WSURL", BASE_URL . "/workspace"); -// Plugin Market -//define("PMURL", "http://codiad.com/plugins.json"); - -// Theme Market -//define("TMURL", "http://codiad.com/themes.json"); +// Marketplace +//define("MARKETURL", "http://market.codiad.com"); // Update Check //define("UPDATEURL", "http://update.codiad.com/?v={VER}&o={OS}&p={PHP}&w={WEB}&a={ACT}"); diff --git a/components/market/class.market.php b/components/market/class.market.php new file mode 100644 index 0000000..f045977 --- /dev/null +++ b/components/market/class.market.php @@ -0,0 +1,291 @@ +local['plugins'] = getJSON('plugins.php'); + $this->local['themes'] = getJSON('themes.php'); + $this->url = Common::getConstant('MARKETURL', $this->url); + if(!file_exists(DATA.'/cache/market.current')) { + file_put_contents(DATA.'/cache/market.current',file_get_contents($this->url)); + copy(DATA.'/cache/market.current',DATA.'/cache/market.last'); + } else { + if (time()-filemtime(DATA.'/cache/market.current') > 24 * 3600) { + copy(DATA.'/cache/market.current',DATA.'/cache/market.last'); + file_put_contents(DATA.'/market.cache',file_get_contents($this->url)); + } + } + $this->old = json_decode(file_get_contents(DATA.'/cache/market.last'),true); + $this->remote = json_decode(file_get_contents(DATA.'/cache/market.current'),true); + foreach($this->remote as $key=>$data) { + if(substr($data['url'],-4) == '.git') { + $data['url'] = substr($data['url'],0,-4); + } + if(file_exists(BASE_PATH.'/'.$data['type'].substr($data['url'],strrpos($data['url'],'/')))) { + $data['folder'] = substr($data['url'],strrpos($data['url'],'/')+1); + } else { + if(file_exists(BASE_PATH.'/'.$data['type'].substr($data['url'],strrpos($data['url'],'/')).'-master')) { + $data['folder'] = substr($data['url'],strrpos($data['url'],'/')+1).'-master'; + } + } + + if(isset($data['folder'])) { + $local = json_decode(file_get_contents(BASE_PATH.'/'.$data['type'].'/'.$data['folder'].'/'.rtrim($data['type'],'s').'.json'),true); + $remote = json_decode(file_get_contents(str_replace('github.com','raw.github.com',$data['url']).'/master/'.rtrim($data['type'],'s').'.json'),true); + $data['version'] = $local[0]['version']; + if($remote[0]['version'] != $local[0]['version']) { + $data['update'] = $remote[0]['version']; + } + } + + $found = false; + foreach($this->old as $key=>$old) { + if($old['name'] == $data['name']) { + $found = true; + break; + } + } + + if(!$found && !isset($data['folder'])) { + $data['new'] = '1'; + } + + array_push($this->tmp, $data); + } + + $this->remote = $this->tmp; + + // Scan plugins directory for missing plugins + foreach (scandir(PLUGINS) as $fname){ + if($fname == '.' || $fname == '..' ){ + continue; + } + if(is_dir(PLUGINS.'/'.$fname)){ + $found = false; + foreach($this->remote as $key=>$data) { + if(isset($data['folder']) && $data['folder'] == $fname) { + $found = true; + break; + } + } + if(!$found && file_exists(PLUGINS . "/" . $fname . "/plugin.json")) { + $data = file_get_contents(PLUGINS . "/" . $fname . "/plugin.json"); + $data = json_decode($data,true); + $data[0]['name'] = $fname; + $data[0]['type'] = 'plugins'; + $data[0]['image'] = ''; + $data[0]['count'] = -1; + $data[0]['description'] = 'Manual Installation found.'; + array_push($this->remote, $data[0]); + } + } + } + + // Scan theme directory for missing plugins + foreach (scandir(THEMES) as $fname){ + if($fname == '.' || $fname == '..' || $fname == 'default'){ + continue; + } + if(is_dir(THEMES.'/'.$fname)){ + $found = false; + foreach($this->remote as $key=>$data) { + if(isset($data['folder']) && $data['folder'] == $fname) { + $found = true; + break; + } + } + if(!$found && file_exists(THEMES . "/" . $fname . "/theme.json")) { + $data = file_get_contents(THEMES . "/" . $fname . "/theme.json"); + $data = json_decode($data,true); + $data[0]['name'] = $fname; + $data[0]['type'] = 'themes'; + $data[0]['image'] = ''; + $data[0]['count'] = -1; + $data[0]['description'] = 'Manual Installation found.'; + array_push($this->remote, $data[0]); + } + } + } + } + + ////////////////////////////////////////////////////////////////// + // Deactivate Plugin + ////////////////////////////////////////////////////////////////// + + public function Deactivate($type, $name){ + saveJSON($type.'.php',array_diff($this->local[$type], array($name))); + echo formatJSEND("success",null); + } + + ////////////////////////////////////////////////////////////////// + // Activate Plugin + ////////////////////////////////////////////////////////////////// + + public function Activate($type, $name){ + $this->local[$type][] = $name; + saveJSON($type.'.php',$this->local[$type]); + echo formatJSEND("success",null); + } + + ////////////////////////////////////////////////////////////////// + // Install Plugin + ////////////////////////////////////////////////////////////////// + + public function Install($type, $name, $repo){ + if(substr($repo,-4) == '.git') { + $repo = substr($repo,0,-4); + } + if(file_put_contents(BASE_PATH.'/'.$type.'/'.$name.'.zip', fopen($repo.'/archive/master.zip', 'r'))) { + $zip = new ZipArchive; + $res = $zip->open(BASE_PATH.'/'.$type.'/'.$name.'.zip'); + // open downloaded archive + if ($res === TRUE) { + // extract archive + if($zip->extractTo(BASE_PATH.'/'.$type) === true) { + $zip->close(); + } else { + die(formatJSEND("error","Unable to open ".$name.".zip")); + } + } else { + die(formatJSEND("error","ZIP Extension not found")); + } + + unlink(BASE_PATH.'/'.$type.'/'.$name.'.zip'); + // Response + $this->Activate($type, substr($repo, strrpos($repo, "/") + 1)."-master"); + } else { + die(formatJSEND("error","Unable to download ".$repo)); + } + } + + ////////////////////////////////////////////////////////////////// + // Remove Plugin + ////////////////////////////////////////////////////////////////// + + public function Remove($type, $name){ + function rrmdir($path){ + return is_file($path)? + @unlink($path): + @array_map('rrmdir',glob($path.'/*'))==@rmdir($path); + } + + rrmdir(BASE_PATH.'/'.$type.'/'.$name); + $this->Deactivate($type, $name); + } + + ////////////////////////////////////////////////////////////////// + // Update Plugin + ////////////////////////////////////////////////////////////////// + + public function Update($type, $name){ + function rrmdir($path){ + return is_file($path)? + @unlink($path): + @array_map('rrmdir',glob($path.'/*'))==@rmdir($path); + } + + 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)){ + if(!file_exists($dest."/".$file)) { + mkdir($dest."/".$file); + } + cpy($source."/".$file, $dest."/".$file, $ign); + } else { + copy($source."/".$file, $dest."/".$file); + } + } + } + closedir($dir_handle); + } else { + copy($source, $dest); + } + } + + if(file_exists(BASE_PATH.'/'.$type.'/'.$name.'/plugin.json')) { + $data = json_decode(file_get_contents(BASE_PATH.'/'.$type.'/'.$name.'/'.rtrim($type, "s").'.json'),true); + $local[0]['url'] = rtrim($local[0]['url'], ".git"); + $local[0]['url'] .= '/archive/master.zip'; + + $ign = array(".",".."); + if(isset($local[0]['exclude'])) { + foreach(explode(",",$local[0]['exclude']) as $exclude) { + array_push($ign, $exclude); + } + } + + if(file_exists(BASE_PATH.'/'.$type.'/_'.session_id()) || mkdir(BASE_PATH.'/'.$type.'/_'.session_id())) { + if(file_put_contents(BASE_PATH.'/'.$type.'/_'.session_id().'/'.$name.'.zip', fopen($local[0]['url'], 'r'))) { + $zip = new ZipArchive; + $res = $zip->open(BASE_PATH.'/'.$type.'/_'.session_id().'/'.$name.'.zip'); + // open downloaded archive + if ($res === TRUE) { + // extract archive + if($zip->extractTo(BASE_PATH.'/'.$type.'/_'.session_id().'') === true) { + $zip->close(); + $srcname = $name; + if(substr($srcname, -6) != "master") { + $srcname = $srcname.'-master'; + } + cpy(BASE_PATH.'/'.$type.'/_'.session_id().'/'.$srcname, BASE_PATH.'/'.$type.'/'.$name, $ign); + } else { + die(formatJSEND("error","Unable to open ".$name.".zip")); + } + } else { + die(formatJSEND("error","ZIP Extension not found")); + } + + rrmdir(BASE_PATH.'/'.$type.'/_'.session_id()); + // Response + echo formatJSEND("success",null); + } else { + die(formatJSEND("error","Unable to download ".$repo)); + } + } else { + die(formatJSEND("error","Unable to create temp dir ")); + } + } else { + echo formatJSEND("error","Unable to find ".$name); + } + } +} diff --git a/components/theme_manager/controller.php b/components/market/controller.php similarity index 77% rename from components/theme_manager/controller.php rename to components/market/controller.php index c7be0aa..ac6f75d 100644 --- a/components/theme_manager/controller.php +++ b/components/market/controller.php @@ -8,7 +8,7 @@ require_once('../../common.php'); - require_once('class.theme_manager.php'); + require_once('class.market.php'); ////////////////////////////////////////////////////////////////// // Verify Session or Key @@ -16,55 +16,55 @@ checkSession(); - $Theme_manager = new Theme_manager(); + $market = new Market(); ////////////////////////////////////////////////////////////////// - // Deactivate Theme + // Deactivate ////////////////////////////////////////////////////////////////// if($_GET['action']=='deactivate'){ if(checkAccess()) { - $Theme_manager->Deactivate($_GET['name']); + $market->Deactivate($_GET['type'], $_GET['name']); } } ////////////////////////////////////////////////////////////////// - // Activate Theme + // Activate ////////////////////////////////////////////////////////////////// if($_GET['action']=='activate'){ if(checkAccess()) { - $Theme_manager->Activate($_GET['name']); + $market->Activate($_GET['type'], $_GET['name']); } } ////////////////////////////////////////////////////////////////// - // Install Theme + // Install ////////////////////////////////////////////////////////////////// if($_GET['action']=='install'){ if(checkAccess()) { - $Theme_manager->Install($_GET['name'], $_GET['repo']); + $market->Install($_GET['type'], $_GET['name'], $_GET['repo']); } } ////////////////////////////////////////////////////////////////// - // Remove Theme + // Remove ////////////////////////////////////////////////////////////////// if($_GET['action']=='remove'){ if(checkAccess()) { - $Theme_manager->Remove($_GET['name']); + $market->Remove($_GET['type'], $_GET['name']); } } ////////////////////////////////////////////////////////////////// - // Update Theme + // Update ////////////////////////////////////////////////////////////////// if($_GET['action']=='update'){ if(checkAccess()) { - $Theme_manager->Update($_GET['name']); + $market->Update($_GET['type'], $_GET['name']); } } diff --git a/components/plugin_manager/dialog.php b/components/market/dialog.php similarity index 66% rename from components/plugin_manager/dialog.php rename to components/market/dialog.php index a6bb894..cb00bae 100644 --- a/components/plugin_manager/dialog.php +++ b/components/market/dialog.php @@ -18,93 +18,88 @@ switch($_GET['action']){ ////////////////////////////////////////////////////////////// - // Plugin Market + // Marketplace ////////////////////////////////////////////////////////////// - case 'market': + case 'list': - require_once('class.plugin_manager.php'); - $pm = new Plugin_manager(); - $market = $pm->Market(); + require_once('class.market.php'); + $market = new Market(); ?> - -
+ +
- - - - + + +
+
+ remote as $data) { + if(!isset($data['category']) || $data['category'] == '') { + $data['category'] = 'Common'; } - if(!array_key_exists($plugin['category'], $marketlist)) { - $marketlist[$plugin['category']] = array(); + if(!array_key_exists($data['type'], $marketplace)) { + $marketplace[$data['type']] = array(); + } + if(!array_key_exists($data['category'], $marketplace[$data['type']])) { + $marketplace[$data['type']][$data['category']] = array(); } - array_push($marketlist[$plugin['category']], $plugin); + array_push($marketplace[$data['type']][$data['category']], $data); } + ksort($marketplace); - ksort($marketlist); - $isDownloadable = (is_writeable(PLUGINS) && extension_loaded('zip') && extension_loaded('openssl') && ini_get('allow_url_fopen') == 1); + function sort_name($a, $b) { return strnatcmp($a['name'], $b['name']); } - foreach($marketlist as $category=>$pluginlist) { - ?> - - - - - - - - - - - - - - - - - - - $data) { + ksort($data); + if($_GET['type'] == 'undefined' || $_GET['type'] == $type) { + foreach($data as $category=>$subdata) { + usort($subdata, 'sort_name'); + foreach($subdata as $addon){ + echo ''; + } + } } - } - } else { - ?> - - -
'; + $left = 0; + if($addon['image'] != '') { + echo '
'; + $left = 150; + } else { + if(isset($addon['new'])) { + $left = $left + 40; + } + } + if(isset($addon['new'])) { + echo '
'; + } + echo ''; + echo '
'.ucfirst(rtrim($type,'s')).' - '.ucfirst($category).' | '.$addon['author'].' | '.$addon['count'].' Users
'; + echo '
'.$addon['description'].'
'; + if(isset($addon['version'])) { + if(!isset($addon['update'])) { + echo '
Latest Version v'.$addon['version'].'
'; + } else { + echo '
'; + } + echo '
'; + } else { + echo '
'; + } + echo '
+
- + + + + + +
diff --git a/components/plugin_manager/init.js b/components/market/init.js similarity index 74% rename from components/plugin_manager/init.js rename to components/market/init.js index cb3b01a..2284cb1 100644 --- a/components/plugin_manager/init.js +++ b/components/market/init.js @@ -9,16 +9,15 @@ var codiad = global.codiad; $(function() { - codiad.plugin_manager.init(); + codiad.market.init(); }); - codiad.plugin_manager = { + codiad.market = { - controller: 'components/plugin_manager/controller.php', - dialog: 'components/plugin_manager/dialog.php', + controller: 'components/market/controller.php', + dialog: 'components/market/dialog.php', - init: function() { - + init: function() { }, ////////////////////////////////////////////////////////////////// @@ -32,13 +31,13 @@ }, ////////////////////////////////////////////////////////////////// - // Open the plugin manager dialog + // Open marketplace ////////////////////////////////////////////////////////////////// - list: function() { + list: function(type) { $('#modal-content form') .die('submit'); // Prevent form bubbling - codiad.modal.load(500, this.dialog + '?action=list'); + codiad.modal.load(800, this.dialog + '?action=list&type='+type); }, ////////////////////////////////////////////////////////////////// @@ -56,13 +55,13 @@ }, ////////////////////////////////////////////////////////////////// - // Install Plugin + // Install ////////////////////////////////////////////////////////////////// - install: function(name, repo) { + install: function(type, name, repo) { var _this = this; $('#modal-content').html('
Installing ' + name + '...

'); - $.get(_this.controller + '?action=install&name=' + name + '&repo=' + repo, function(data) { + $.get(_this.controller + '?action=install&type=' + type + '&name=' + name + '&repo=' + repo, function(data) { var response = codiad.jsend.parse(data); if (response == 'error') { codiad.message.error(response.message); @@ -73,12 +72,13 @@ }, ////////////////////////////////////////////////////////////////// - // Remove Plugin + // Remove ////////////////////////////////////////////////////////////////// - remove: function(name) { + remove: function(type, name) { var _this = this; - $.get(_this.controller + '?action=remove&name=' + name, function(data) { + $('#modal-content').html('
Deleting ' + name + '...

'); + $.get(_this.controller + '?action=remove&type=' + type + '&name=' + name, function(data) { var response = codiad.jsend.parse(data); if (response == 'error') { codiad.message.error(response.message); @@ -88,13 +88,13 @@ }, ////////////////////////////////////////////////////////////////// - // Update Plugin + // Update ////////////////////////////////////////////////////////////////// - update: function(name) { + update: function(type, name) { var _this = this; $('#modal-content').html('
Updating ' + name + '...

'); - $.get(_this.controller + '?action=update&name=' + name, function(data) { + $.get(_this.controller + '?action=update&type=' + type + '&name=' + name, function(data) { var response = codiad.jsend.parse(data); if (response == 'error') { codiad.message.error(response.message); @@ -104,12 +104,12 @@ }, ////////////////////////////////////////////////////////////////// - // Activate Plugin + // Activate ////////////////////////////////////////////////////////////////// - activate: function(name) { + activate: function(type, name) { var _this = this; - $.get(this.controller + '?action=activate&name=' + name, function(data) { + $.get(this.controller + '?action=activate&type=' + type + '&name=' + name, function(data) { var response = codiad.jsend.parse(data); if (response != 'error') { _this.list(); @@ -118,12 +118,12 @@ }, ////////////////////////////////////////////////////////////////// - // Deactivate Plugin + // Deactivate ////////////////////////////////////////////////////////////////// - deactivate: function(name) { + deactivate: function(type, name) { var _this = this; - $.get(this.controller + '?action=deactivate&name=' + name, function(data) { + $.get(this.controller + '?action=deactivate&type=' + type + '&name=' + name, function(data) { var response = codiad.jsend.parse(data); if (response != 'error') { _this.list(); diff --git a/components/plugin_manager/class.plugin_manager.php b/components/plugin_manager/class.plugin_manager.php deleted file mode 100644 index 489a5f0..0000000 --- a/components/plugin_manager/class.plugin_manager.php +++ /dev/null @@ -1,200 +0,0 @@ -plugins = getJSON('plugins.php'); - $this->market = Common::getConstant('PMURL', $this->market); - } - - ////////////////////////////////////////////////////////////////// - // Get Market list - ////////////////////////////////////////////////////////////////// - - public function Market(){ - return json_decode(file_get_contents($this->market),true); - } - - ////////////////////////////////////////////////////////////////// - // Deactivate Plugin - ////////////////////////////////////////////////////////////////// - - public function Deactivate($name){ - $revised_array = array(); - foreach($this->plugins as $plugin){ - if($plugin!=$name){ - $revised_array[] = $plugin; - } - } - // Save array back to JSON - saveJSON('plugins.php',$revised_array); - // Response - echo formatJSEND("success",null); - } - - ////////////////////////////////////////////////////////////////// - // Activate Plugin - ////////////////////////////////////////////////////////////////// - - public function Activate($name){ - $this->plugins[] = $name; - saveJSON('plugins.php',$this->plugins); - // Response - echo formatJSEND("success",null); - } - - ////////////////////////////////////////////////////////////////// - // Install Plugin - ////////////////////////////////////////////////////////////////// - - public function Install($name, $repo){ - if(substr($repo,-4) == '.git') { - $repo = substr($repo,0,-4); - } - if(file_put_contents(PLUGINS.'/'.$name.'.zip', fopen($repo.'/archive/master.zip', 'r'))) { - $zip = new ZipArchive; - $res = $zip->open(PLUGINS.'/'.$name.'.zip'); - // open downloaded archive - if ($res === TRUE) { - // extract archive - if($zip->extractTo(PLUGINS) === true) { - $zip->close(); - } else { - die(formatJSEND("error","Unable to open ".$name.".zip")); - } - } else { - die(formatJSEND("error","ZIP Extension not found")); - } - - unlink(PLUGINS.'/'.$name.'.zip'); - // Response - $this->Activate(substr($repo, strrpos($repo, "/") + 1)."-master"); - } else { - die(formatJSEND("error","Unable to download ".$repo)); - } - } - - ////////////////////////////////////////////////////////////////// - // Remove Plugin - ////////////////////////////////////////////////////////////////// - - public function Remove($name){ - function rrmdir($path){ - return is_file($path)? - @unlink($path): - @array_map('rrmdir',glob($path.'/*'))==@rmdir($path); - } - - rrmdir(PLUGINS.'/'.$name); - $this->Deactivate($name); - } - - ////////////////////////////////////////////////////////////////// - // Update Plugin - ////////////////////////////////////////////////////////////////// - - public function Update($name){ - function rrmdir($path){ - return is_file($path)? - @unlink($path): - @array_map('rrmdir',glob($path.'/*'))==@rmdir($path); - } - - 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)){ - if(!file_exists($dest."/".$file)) { - mkdir($dest."/".$file); - } - cpy($source."/".$file, $dest."/".$file, $ign); - } else { - copy($source."/".$file, $dest."/".$file); - } - } - } - closedir($dir_handle); - } else { - copy($source, $dest); - } - } - - 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'; - - $ign = array(".",".."); - if(isset($data[0]['exclude'])) { - foreach(explode(",",$data[0]['exclude']) as $exclude) { - array_push($ign, $exclude); - } - } - - if(file_exists(PLUGINS.'/_'.session_id()) || mkdir(PLUGINS.'/_'.session_id())) { - if(file_put_contents(PLUGINS.'/_'.session_id().'/'.$name.'.zip', fopen($data[0]['url'], 'r'))) { - $zip = new ZipArchive; - $res = $zip->open(PLUGINS.'/_'.session_id().'/'.$name.'.zip'); - // open downloaded archive - if ($res === TRUE) { - // extract archive - if($zip->extractTo(PLUGINS.'/_'.session_id().'') === true) { - $zip->close(); - $srcname = $name; - if(substr($srcname, -6) != "master") { - $srcname = $srcname.'-master'; - } - cpy(PLUGINS.'/_'.session_id().'/'.$srcname, PLUGINS.'/'.$name, $ign); - } else { - die(formatJSEND("error","Unable to open ".$name.".zip")); - } - } else { - die(formatJSEND("error","ZIP Extension not found")); - } - - rrmdir(PLUGINS.'/_'.session_id()); - // Response - echo formatJSEND("success",null); - } else { - die(formatJSEND("error","Unable to download ".$repo)); - } - } else { - die(formatJSEND("error","Unable to create temp dir ")); - } - } else { - echo formatJSEND("error","Unable to find plugin ".$name); - } - } -} diff --git a/components/plugin_manager/controller.php b/components/plugin_manager/controller.php deleted file mode 100644 index 3282fdc..0000000 --- a/components/plugin_manager/controller.php +++ /dev/null @@ -1,71 +0,0 @@ -Deactivate($_GET['name']); - } - } - - ////////////////////////////////////////////////////////////////// - // Activate Plugin - ////////////////////////////////////////////////////////////////// - - if($_GET['action']=='activate'){ - if(checkAccess()) { - $Plugin_manager->Activate($_GET['name']); - } - } - - ////////////////////////////////////////////////////////////////// - // Install Plugin - ////////////////////////////////////////////////////////////////// - - if($_GET['action']=='install'){ - if(checkAccess()) { - $Plugin_manager->Install($_GET['name'], $_GET['repo']); - } - } - - ////////////////////////////////////////////////////////////////// - // Remove Plugin - ////////////////////////////////////////////////////////////////// - - if($_GET['action']=='remove'){ - if(checkAccess()) { - $Plugin_manager->Remove($_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/right_bar.json b/components/right_bar.json index 3cbd8ce..65afcd5 100755 --- a/components/right_bar.json +++ b/components/right_bar.json @@ -40,14 +40,9 @@ "onclick": "codiad.modal.load(400, 'components/editor/dialog.php?action=settings');codiad.modal.hideOverlay();" }, { - "title": "Plugins", - "icon": "icon-tag", - "onclick": "codiad.plugin_manager.list();" - }, - { - "title": "Themes", - "icon": "icon-picture", - "onclick": "codiad.theme_manager.list();" + "title": "Marketplace", + "icon": "icon-cloud", + "onclick": "codiad.market.list();" }, { "title": "break", diff --git a/components/theme_manager/class.theme_manager.php b/components/theme_manager/class.theme_manager.php deleted file mode 100644 index 6a87393..0000000 --- a/components/theme_manager/class.theme_manager.php +++ /dev/null @@ -1,200 +0,0 @@ -themes = getJSON('themes.php'); - $this->market = Common::getConstant('TMURL', $this->market); - } - - ////////////////////////////////////////////////////////////////// - // Get Market list - ////////////////////////////////////////////////////////////////// - - public function Market(){ - return json_decode(file_get_contents($this->market),true); - } - - ////////////////////////////////////////////////////////////////// - // Deactivate Theme - ////////////////////////////////////////////////////////////////// - - public function Deactivate($name){ - $revised_array = array(); - foreach($this->themes as $theme){ - if($theme!=$name){ - $revised_array[] = $theme; - } - } - // Save array back to JSON - saveJSON('themes.php',$revised_array); - // Response - echo formatJSEND("success",null); - } - - ////////////////////////////////////////////////////////////////// - // Activate Theme - ////////////////////////////////////////////////////////////////// - - public function Activate($name){ - $this->themes[] = $name; - saveJSON('themes.php',$this->themes); - // Response - echo formatJSEND("success",null); - } - - ////////////////////////////////////////////////////////////////// - // Install Theme - ////////////////////////////////////////////////////////////////// - - public function Install($name, $repo){ - if(substr($repo,-4) == '.git') { - $repo = substr($repo,0,-4); - } - if(file_put_contents(THEMES.'/'.$name.'.zip', fopen($repo.'/archive/master.zip', 'r'))) { - $zip = new ZipArchive; - $res = $zip->open(THEMES.'/'.$name.'.zip'); - // open downloaded archive - if ($res === TRUE) { - // extract archive - if($zip->extractTo(THEMES) === true) { - $zip->close(); - } else { - die(formatJSEND("error","Unable to open ".$name.".zip")); - } - } else { - die(formatJSEND("error","ZIP Extension not found")); - } - - unlink(THEMES.'/'.$name.'.zip'); - // Response - $this->Activate(substr($repo, strrpos($repo, "/") + 1)."-master"); - } else { - die(formatJSEND("error","Unable to download ".$repo)); - } - } - - ////////////////////////////////////////////////////////////////// - // Remove theme - ////////////////////////////////////////////////////////////////// - - public function Remove($name){ - function rrmdir($path){ - return is_file($path)? - @unlink($path): - @array_map('rrmdir',glob($path.'/*'))==@rmdir($path); - } - - rrmdir(THEMES.'/'.$name); - $this->Deactivate($name); - } - - ////////////////////////////////////////////////////////////////// - // Update Theme - ////////////////////////////////////////////////////////////////// - - public function Update($name){ - function rrmdir($path){ - return is_file($path)? - @unlink($path): - @array_map('rrmdir',glob($path.'/*'))==@rmdir($path); - } - - 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)){ - if(!file_exists($dest."/".$file)) { - mkdir($dest."/".$file); - } - cpy($source."/".$file, $dest."/".$file, $ign); - } else { - copy($source."/".$file, $dest."/".$file); - } - } - } - closedir($dir_handle); - } else { - copy($source, $dest); - } - } - - if(file_exists(THEMES.'/'.$name.'/theme.json')) { - $data = json_decode(file_get_contents(THEMES.'/'.$name.'/theme.json'),true); - if(substr($data[0]['url'],-4) == '.git') { - $data[0]['url'] = substr($data[0]['url'],0,-4); - } - $data[0]['url'] .= '/archive/master.zip'; - - $ign = array(".",".."); - if(isset($data[0]['exclude'])) { - foreach(explode(",",$data[0]['exclude']) as $exclude) { - array_push($ign, $exclude); - } - } - - if(file_exists(THEMES.'/_'.session_id()) || mkdir(THEMES.'/_'.session_id())) { - if(file_put_contents(THEMES.'/_'.session_id().'/'.$name.'.zip', fopen($data[0]['url'], 'r'))) { - $zip = new ZipArchive; - $res = $zip->open(THEMES.'/_'.session_id().'/'.$name.'.zip'); - // open downloaded archive - if ($res === TRUE) { - // extract archive - if($zip->extractTo(THEMES.'/_'.session_id().'') === true) { - $zip->close(); - $srcname = $name; - if(substr($srcname, -6) != "master") { - $srcname = $srcname.'-master'; - } - cpy(THEMES.'/_'.session_id().'/'.$srcname, THEMES.'/'.$name, $ign); - } else { - die(formatJSEND("error","Unable to open ".$name.".zip")); - } - } else { - die(formatJSEND("error","ZIP Extension not found")); - } - - rrmdir(THEMES.'/_'.session_id()); - // Response - echo formatJSEND("success",null); - } else { - die(formatJSEND("error","Unable to download ".$repo)); - } - } else { - die(formatJSEND("error","Unable to create temp dir ")); - } - } else { - echo formatJSEND("error","Unable to find theme ".$name); - } - } -} diff --git a/components/theme_manager/dialog.php b/components/theme_manager/dialog.php deleted file mode 100644 index a07981c..0000000 --- a/components/theme_manager/dialog.php +++ /dev/null @@ -1,313 +0,0 @@ -Market(); - ?> - -
- - - - - - - - $themelist) { - ?> - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
n/a
-
- - - diff --git a/components/theme_manager/init.js b/components/theme_manager/init.js deleted file mode 100644 index 573e991..0000000 --- a/components/theme_manager/init.js +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright (c) Codiad & daeks (codiad.com), distributed - * as-is and without warranty under the MIT License. See - * [root]/license.txt for more. This information must remain intact. - */ - -(function(global, $){ - - var codiad = global.codiad; - - $(function() { - codiad.theme_manager.init(); - }); - - codiad.theme_manager = { - - controller: 'components/theme_manager/controller.php', - dialog: 'components/theme_manager/dialog.php', - - init: function() { - - }, - - ////////////////////////////////////////////////////////////////// - // Open the theme manager market - ////////////////////////////////////////////////////////////////// - - market: function() { - $('#modal-content form') - .die('submit'); // Prevent form bubbling - codiad.modal.load(500, this.dialog + '?action=market'); - }, - - ////////////////////////////////////////////////////////////////// - // Open the theme manager dialog - ////////////////////////////////////////////////////////////////// - - list: function() { - $('#modal-content form') - .die('submit'); // Prevent form bubbling - codiad.modal.load(500, this.dialog + '?action=list'); - }, - - ////////////////////////////////////////////////////////////////// - // Checks for theme updates - ////////////////////////////////////////////////////////////////// - - check: function() { - $('#modal-content form') - .die('submit'); // Prevent form bubbling - codiad.modal.load(500, this.dialog + '?action=check'); - }, - - openInBrowser: function(path) { - window.open(path, '_newtab'); - }, - - ////////////////////////////////////////////////////////////////// - // Install theme - ////////////////////////////////////////////////////////////////// - - install: function(name, repo) { - var _this = this; - $('#modal-content').html('
Installing ' + name + '...

'); - $.get(_this.controller + '?action=install&name=' + name + '&repo=' + repo, function(data) { - var response = codiad.jsend.parse(data); - if (response == 'error') { - codiad.message.error(response.message); - } else { - _this.list(); - } - }); - }, - - ////////////////////////////////////////////////////////////////// - // Remove theme - ////////////////////////////////////////////////////////////////// - - remove: function(name) { - var _this = this; - $.get(_this.controller + '?action=remove&name=' + name, function(data) { - var response = codiad.jsend.parse(data); - if (response == 'error') { - codiad.message.error(response.message); - } - _this.list(); - }); - }, - - ////////////////////////////////////////////////////////////////// - // Update theme - ////////////////////////////////////////////////////////////////// - - update: function(name) { - var _this = this; - $('#modal-content').html('
Updating ' + 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 theme - ////////////////////////////////////////////////////////////////// - - activate: function(name) { - var _this = this; - $.get(this.controller + '?action=activate&name=' + name, function(data) { - var response = codiad.jsend.parse(data); - if (response != 'error') { - _this.list(); - } - }); - }, - - ////////////////////////////////////////////////////////////////// - // Deactivate theme - ////////////////////////////////////////////////////////////////// - - deactivate: function(name) { - var _this = this; - $.get(this.controller + '?action=deactivate&name=' + name, function(data) { - var response = codiad.jsend.parse(data); - if (response != 'error') { - _this.list(); - } - }); - } - }; -})(this, jQuery); diff --git a/config.example.php b/config.example.php index 0a7b865..72dc7f5 100644 --- a/config.example.php +++ b/config.example.php @@ -43,11 +43,8 @@ define("WORKSPACE", BASE_PATH . "/workspace"); // URLS define("WSURL", BASE_URL . "/workspace"); -// Plugin Market -//define("PMURL", "http://codiad.com/plugins.json"); - -// Theme Market -//define("TMURL", "http://codiad.com/themes.json"); +// Marketplace +//define("MARKETURL", "http://market.codiad.com"); // Update Check //define("UPDATEURL", "http://update.codiad.com/?v={VER}&o={OS}&p={PHP}&w={WEB}&a={ACT}"); diff --git a/plugins/README.md b/plugins/README.md deleted file mode 100644 index 5325aba..0000000 --- a/plugins/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Plugins - -The plugins directory is where you place plugins :-) - -[GET SOME...](http://www.codiad.com/plugins.html) \ No newline at end of file diff --git a/themes/default/images/new.png b/themes/default/images/new.png new file mode 100644 index 0000000000000000000000000000000000000000..1fec6c9a2da863b31b3a228812948d762fb08513 GIT binary patch literal 2782 zcmV<43L*80P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02*{fSaefwW^{L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0200 Subject: [PATCH 2/3] added manual repo --- components/market/class.market.php | 2 ++ components/market/dialog.php | 4 ++-- components/market/init.js | 22 +++++++++++++--------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/components/market/class.market.php b/components/market/class.market.php index f045977..b449423 100644 --- a/components/market/class.market.php +++ b/components/market/class.market.php @@ -109,6 +109,7 @@ class Market extends Common { $data = file_get_contents(PLUGINS . "/" . $fname . "/plugin.json"); $data = json_decode($data,true); $data[0]['name'] = $fname; + $data[0]['folder'] = $fname; $data[0]['type'] = 'plugins'; $data[0]['image'] = ''; $data[0]['count'] = -1; @@ -135,6 +136,7 @@ class Market extends Common { $data = file_get_contents(THEMES . "/" . $fname . "/theme.json"); $data = json_decode($data,true); $data[0]['name'] = $fname; + $data[0]['folder'] = $fname; $data[0]['type'] = 'themes'; $data[0]['image'] = ''; $data[0]['count'] = -1; diff --git a/components/market/dialog.php b/components/market/dialog.php index cb00bae..b853720 100644 --- a/components/market/dialog.php +++ b/components/market/dialog.php @@ -96,8 +96,8 @@
- - + +
Installing ' + name + '...

'); - $.get(_this.controller + '?action=install&type=' + type + '&name=' + name + '&repo=' + repo, function(data) { - var response = codiad.jsend.parse(data); - if (response == 'error') { - codiad.message.error(response.message); - } else { - _this.list(); - } - }); + if(repo != '') { + $('#modal-content').html('
Installing ' + name + '...

'); + $.get(_this.controller + '?action=install&type=' + type + '&name=' + name + '&repo=' + repo, function(data) { + var response = codiad.jsend.parse(data); + if (response == 'error') { + codiad.message.error(response.message); + } else { + _this.list(); + } + }); + } else { + codiad.message.error('No Repository URL'); + } }, ////////////////////////////////////////////////////////////////// From 7a9e3b4fc3ae482f79e2947df7008ba6505e197f Mon Sep 17 00:00:00 2001 From: daeks Date: Wed, 7 Aug 2013 17:47:42 +0200 Subject: [PATCH 3/3] install manually --- components/market/class.market.php | 13 +++++++++++++ components/market/init.js | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/market/class.market.php b/components/market/class.market.php index b449423..3a7e380 100644 --- a/components/market/class.market.php +++ b/components/market/class.market.php @@ -174,6 +174,19 @@ class Market extends Common { if(substr($repo,-4) == '.git') { $repo = substr($repo,0,-4); } + if($type == '') { + $file_headers = @get_headers(str_replace('github.com','raw.github.com',$repo.'/master/plugin.json')); + if($file_headers[0] != 'HTTP/1.1 404 Not Found') { + $type = 'plugins'; + } else { + $file_headers = @get_headers(str_replace('github.com','raw.github.com',$repo.'/master/theme.json')); + if($file_headers[0] != 'HTTP/1.1 404 Not Found') { + $type = 'themes'; + } else { + die(formatJSEND("error","No type for ".$repo)); + } + } + } if(file_put_contents(BASE_PATH.'/'.$type.'/'.$name.'.zip', fopen($repo.'/archive/master.zip', 'r'))) { $zip = new ZipArchive; $res = $zip->open(BASE_PATH.'/'.$type.'/'.$name.'.zip'); diff --git a/components/market/init.js b/components/market/init.js index 1c0779e..cce14f3 100644 --- a/components/market/init.js +++ b/components/market/init.js @@ -66,9 +66,8 @@ var response = codiad.jsend.parse(data); if (response == 'error') { codiad.message.error(response.message); - } else { - _this.list(); } + _this.list(); }); } else { codiad.message.error('No Repository URL');