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 { open_in_new + = 10 && $is_local) { ?> + + +
@@ -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 { open_in_new + = 10 && $is_local) { ?> + + +
@@ -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",