enable/disable plugins from admin page
This commit is contained in:
parent
b1184f3fde
commit
5dc8fbccb2
54
boot.php
54
boot.php
|
@ -453,6 +453,37 @@ function system_unavailable() {
|
||||||
killme();
|
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
|
// Primarily involved with database upgrade, but also sets the
|
||||||
// base url for use in cmdline programs which don't have
|
// base url for use in cmdline programs which don't have
|
||||||
// $_SERVER variables, and synchronising the state of installed plugins.
|
// $_SERVER variables, and synchronising the state of installed plugins.
|
||||||
|
@ -538,16 +569,7 @@ function check_config(&$a) {
|
||||||
if(count($installed)) {
|
if(count($installed)) {
|
||||||
foreach($installed as $i) {
|
foreach($installed as $i) {
|
||||||
if(! in_array($i['name'],$plugins_arr)) {
|
if(! in_array($i['name'],$plugins_arr)) {
|
||||||
logger("Addons: uninstalling " . $i['name']);
|
uninstall_plugin($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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$installed_arr[] = $i['name'];
|
$installed_arr[] = $i['name'];
|
||||||
|
@ -557,17 +579,7 @@ function check_config(&$a) {
|
||||||
if(count($plugins_arr)) {
|
if(count($plugins_arr)) {
|
||||||
foreach($plugins_arr as $p) {
|
foreach($plugins_arr as $p) {
|
||||||
if(! in_array($p,$installed_arr)) {
|
if(! in_array($p,$installed_arr)) {
|
||||||
logger("Addons: installing " . $p);
|
install_plugin($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)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
images/icons.png
BIN
images/icons.png
Binary file not shown.
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 10 KiB |
|
@ -310,7 +310,58 @@ function admin_page_users(&$a){
|
||||||
|
|
||||||
function admin_page_plugins(&$a){
|
function admin_page_plugins(&$a){
|
||||||
|
|
||||||
/* all plugins */
|
/**
|
||||||
|
* Single plugin
|
||||||
|
*/
|
||||||
|
if ($a->argc == 3){
|
||||||
|
$plugin = $a->argv[2];
|
||||||
|
if (!is_file("addon/$plugin/$plugin.php")){
|
||||||
|
notice( t("Item not found.") );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x($_GET,"a") && $_GET['a']=="t"){
|
||||||
|
// Toggle plugin status
|
||||||
|
$idx = array_search($plugin, $a->plugins);
|
||||||
|
if ($idx){
|
||||||
|
unset($a->plugins[$idx]);
|
||||||
|
uninstall_plugin($plugin);
|
||||||
|
} else {
|
||||||
|
$a->plugins[] = $plugin;
|
||||||
|
install_plugin($plugin);
|
||||||
|
}
|
||||||
|
set_config("system","addon", implode(", ",$a->plugins));
|
||||||
|
goaway($a->get_baseurl() . '/admin/plugins' );
|
||||||
|
return; // NOTREACHED
|
||||||
|
}
|
||||||
|
// display plugin details
|
||||||
|
|
||||||
|
|
||||||
|
if (in_array($plugin, $a->plugins)){
|
||||||
|
$status="on"; $action= t("Disable");
|
||||||
|
} else {
|
||||||
|
$status="off"; $action= t("Enable");
|
||||||
|
}
|
||||||
|
|
||||||
|
$t = get_markup_template("admin_plugins_details.tpl");
|
||||||
|
return replace_macros($t, array(
|
||||||
|
'$title' => t('Administration'),
|
||||||
|
'$page' => t('Plugins'),
|
||||||
|
'$toggle' => t('Toggle'),
|
||||||
|
'$baseurl' => $a->get_baseurl(),
|
||||||
|
|
||||||
|
'$plugin' => $plugin,
|
||||||
|
'$status' => $status,
|
||||||
|
'$action' => $action
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List plugins
|
||||||
|
*/
|
||||||
|
|
||||||
$plugins = array();
|
$plugins = array();
|
||||||
$files = glob("addon/*/");
|
$files = glob("addon/*/");
|
||||||
if($files) {
|
if($files) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user