summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-03 19:35:11 +0300
committerAndrew Dolgov <[email protected]>2021-03-03 19:35:11 +0300
commit0cb719a40447e30011142714d5e5ce55c051a118 (patch)
treeb629f55148996ee6e4aedab227bb161f58b55db6
parentdfdb746a76231bfb4c8066328bf99cd54f83783c (diff)
add basic local plugin uninstaller
-rwxr-xr-xclasses/pluginhost.php6
-rw-r--r--classes/pref/prefs.php35
-rw-r--r--js/PrefHelpers.js16
3 files changed, 56 insertions, 1 deletions
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index bd0e9f4d8..746b780e4 100755
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -623,4 +623,10 @@ class PluginHost {
user_error("get_public_method_url: requested method '$method' of '" . get_class($sender) . "' is private.");
}
}
+
+ function is_local(Plugin $plugin) {
+ $ref = new ReflectionClass(get_class($plugin));
+
+ return basename(dirname(dirname($ref->getFileName()))) == "plugins.local";
+ }
}
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index 275f41656..09fbce9a1 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -796,6 +796,7 @@ class Pref_Prefs extends Handler_Protected {
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
+ $is_local = $tmppluginhost->is_local($plugin);
$version = htmlspecialchars($this->_get_plugin_version($plugin));
if ($about[3] ?? false) {
@@ -822,6 +823,14 @@ class Pref_Prefs extends Handler_Protected {
<i class='material-icons'>open_in_new</i> <?= __("More info...") ?></button>
<?php } ?>
+ <?php if ($_SESSION["access_level"] >= 10 && $is_local) { ?>
+ <button dojoType='dijit.form.Button'
+ onclick='Helpers.Plugins.uninstall("<?= htmlspecialchars($name) ?>")'>
+ <?= \Controls\icon("delete") ?>
+ <?= __("Uninstall") ?>
+ </button>
+ <?php } ?>
+
<?php if ($version) { ?>
<div dojoType='dijit.Tooltip' connectId='PLABEL-<?= htmlspecialchars($name) ?>' position='after'>
<?= $version ?>
@@ -842,6 +851,7 @@ class Pref_Prefs extends Handler_Protected {
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
+ $is_local = $tmppluginhost->is_local($plugin);
$version = htmlspecialchars($this->_get_plugin_version($plugin));
if (empty($about[3]) || $about[3] == false) {
@@ -889,6 +899,14 @@ class Pref_Prefs extends Handler_Protected {
<i class='material-icons'>open_in_new</i> <?= __("More info...") ?></button>
<?php } ?>
+ <?php if ($_SESSION["access_level"] >= 10 && $is_local) { ?>
+ <button dojoType='dijit.form.Button'
+ onclick='Helpers.Plugins.uninstall("<?= htmlspecialchars($name) ?>")'>
+ <?= \Controls\icon("delete") ?>
+ <?= __("Uninstall") ?>
+ </button>
+ <?php } ?>
+
<?php if ($version) { ?>
<div dojoType='dijit.Tooltip' connectId='PLABEL-<?= htmlspecialchars($name) ?>' position='after'>
<?= $version ?>
@@ -1235,9 +1253,24 @@ class Pref_Prefs extends Handler_Protected {
}
}
+ function uninstallPlugin() {
+ if ($_SESSION["access_level"] >= 10) {
+ $plugin_name = basename(clean($_REQUEST['plugin']));
+ $status = 0;
+
+ $plugin_dir = dirname(dirname(__DIR__)) . "/plugins.local/$plugin_name";
+
+ if (is_dir($plugin_dir)) {
+ $status = $this->_recursive_rmdir($plugin_dir);
+ }
+
+ print json_encode(['status' => $status]);
+ }
+ }
+
function installPlugin() {
if ($_SESSION["access_level"] >= 10 && Config::get(Config::ENABLE_PLUGIN_INSTALLER)) {
- $plugin_name = clean($_REQUEST['plugin']);
+ $plugin_name = basename(clean($_REQUEST['plugin']));
$all_plugins = $this->_get_available_plugins();
$plugin_dir = dirname(dirname(__DIR__)) . "/plugins.local";
diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js
index e6a37c6e8..241bb6e71 100644
--- a/js/PrefHelpers.js
+++ b/js/PrefHelpers.js
@@ -349,6 +349,22 @@ const Helpers = {
}
});
},
+ uninstall: function(plugin) {
+ const msg = __("Uninstall plugin %s?").replace("%s", plugin);
+
+ if (confirm(msg)) {
+ Notify.progress("Loading, please wait...");
+
+ xhr.json("backend.php", {op: "pref-prefs", method: "uninstallPlugin", plugin: plugin}, (reply) => {
+ if (reply && reply.status == 1)
+ Helpers.Prefs.refresh();
+ else {
+ Notify.error("Plugin uninstallation failed.");
+ }
+ });
+
+ }
+ },
install: function() {
const dialog = new fox.SingleUseDialog({
PI_RES_ALREADY_INSTALLED: "PI_RES_ALREADY_INSTALLED",