From 5dc8fbccb29169601ad5fed2b5289631e32e5ac5 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 14 Jun 2011 11:16:27 +0200 Subject: enable/disable plugins from admin page --- boot.php | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'boot.php') diff --git a/boot.php b/boot.php index 8edc74910..42b0ca41e 100644 --- a/boot.php +++ b/boot.php @@ -453,6 +453,37 @@ function system_unavailable() { killme(); }} + +// install and uninstall plugin +if (! function_exists('uninstall_plugin')){ +function uninstall_plugin($plugin){ + logger("Addons: uninstalling " . $plugin); + q("DELETE FROM `addon` WHERE `name` = '%s' LIMIT 1", + dbesc($plugin) + ); + + @include_once('addon/' . $plugin . '/' . $plugin . '.php'); + if(function_exists($plugin . '_uninstall')) { + $func = $plugin . '_uninstall'; + $func(); + } +}} + +if (! function_exists('install_plugin')){ +function install_plugin($plugin){ + logger("Addons: installing " . $plugin); + $t = filemtime('addon/' . $plugin . '/' . $plugin . '.php'); + @include_once('addon/' . $plugin . '/' . $plugin . '.php'); + if(function_exists($plugin . '_install')) { + $func = $plugin . '_install'; + $func(); + $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`) VALUES ( '%s', 1, %d ) ", + dbesc($plugin), + intval($t) + ); + } +}} + // Primarily involved with database upgrade, but also sets the // base url for use in cmdline programs which don't have // $_SERVER variables, and synchronising the state of installed plugins. @@ -538,16 +569,7 @@ function check_config(&$a) { if(count($installed)) { foreach($installed as $i) { if(! in_array($i['name'],$plugins_arr)) { - logger("Addons: uninstalling " . $i['name']); - q("DELETE FROM `addon` WHERE `id` = %d LIMIT 1", - intval($i['id']) - ); - - @include_once('addon/' . $i['name'] . '/' . $i['name'] . '.php'); - if(function_exists($i['name'] . '_uninstall')) { - $func = $i['name'] . '_uninstall'; - $func(); - } + uninstall_plugin($i['name']); } else $installed_arr[] = $i['name']; @@ -557,17 +579,7 @@ function check_config(&$a) { if(count($plugins_arr)) { foreach($plugins_arr as $p) { if(! in_array($p,$installed_arr)) { - logger("Addons: installing " . $p); - $t = filemtime('addon/' . $p . '/' . $p . '.php'); - @include_once('addon/' . $p . '/' . $p . '.php'); - if(function_exists($p . '_install')) { - $func = $p . '_install'; - $func(); - $r = q("INSERT INTO `addon` (`name`, `installed`, `timestamp`) VALUES ( '%s', 1, %d ) ", - dbesc($p), - intval($t) - ); - } + install_plugin($p); } } } -- cgit v1.2.3 From 00e142e4f753005a8b4003585c6a88548f006315 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Tue, 14 Jun 2011 14:21:43 +0200 Subject: Load plugin info from plugin file. Show README.md or README from plugin dir in plugin details page --- boot.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'boot.php') diff --git a/boot.php b/boot.php index 42b0ca41e..5d45de36f 100644 --- a/boot.php +++ b/boot.php @@ -2828,3 +2828,55 @@ function is_site_admin() { return false; }} +/* + * parse plugin comment in search of plugin infos. + * like + * + * * Name: Plugin + * * Description: A plugin which plugs in + * * Version: 1.2.3 + * * Author: John + * * Author: Jane + * * + */ + +if (! function_exists('get_plugin_info')){ +function get_plugin_info($plugin){ + if (!is_file("addon/$plugin/$plugin.php")) return false; + + $f = file_get_contents("addon/$plugin/$plugin.php"); + $r = preg_match("|/\*.*\*/|msU", $f, $m); + + $info=Array( + 'name' => $plugin, + 'description' => "", + 'author' => array(), + 'version' => "" + ); + + if ($r){ + $ll = explode("\n", $m[0]); + foreach( $ll as $l ) { + $l = trim($l,"\t\n\r */"); + if ($l!=""){ + list($k,$v) = array_map("trim", explode(":",$l,2)); + $k= strtolower($k); + if ($k=="author"){ + $r=preg_match("|([^<]+)<([^>]+)>|", $v, $m); + if ($r) { + $info['author'][] = array('name'=>$m[1], 'link'=>$m[2]); + } else { + $info['author'][] = array('name'=>$v); + } + } else { + if (array_key_exists($k,$info)){ + $info[$k]=$v; + } + } + + } + } + + } + return $info; +}} -- cgit v1.2.3 From c94b809634cd92c69be3483c935e6741b7d0c090 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Thu, 16 Jun 2011 12:14:04 +0200 Subject: fix a small php notice. --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'boot.php') diff --git a/boot.php b/boot.php index 5d45de36f..ff4224cfc 100644 --- a/boot.php +++ b/boot.php @@ -2779,7 +2779,7 @@ function unamp($s) { if(! function_exists('lang_selector')) { function lang_selector() { global $lang; - $o .= '
'; + $o = '
'; $o .= '