diff --git a/actions/plugindisable.php b/actions/plugindisable.php index a1056caa8a..a7364511d2 100644 --- a/actions/plugindisable.php +++ b/actions/plugindisable.php @@ -38,6 +38,52 @@ defined('STATUSNET') || die(); */ class PlugindisableAction extends PluginenableAction { + /** + * Handle request + * + * Disables the plugin and returns results. + * + * @return void + * @throws ClientException + */ + function handle() + { + if (PluginList::isPluginLoaded($this->plugin)) { + $config_file = INSTALLDIR . DIRECTORY_SEPARATOR . 'config.php'; + $config_lines = file($config_file, FILE_IGNORE_NEW_LINES); + foreach($config_lines as $key => $line) { + // We are doing it this way to avoid deleting things we shouldn't + $line = str_replace('addPlugin(\''.$this->plugin.'\');', '', $line); + $config_lines[$key] = $line; + if($line === ' // Added by sysadmin\'s Plugin UI.') { + unset($config_lines[$key]); + } + } + $new_config_data = implode(PHP_EOL, $config_lines); + if (!file_put_contents($config_file, $new_config_data)) { + $this->clientError(_m('No permissions for writing to config.php')); + } + } + $key = 'disable-' . $this->plugin; + Config::save('plugins', $key, $this->overrideValue()); + + // @fixme this is a pretty common pattern and should be refactored down + if ($this->boolean('ajax')) { + $this->startHTML('text/xml;charset=utf-8'); + $this->elementStart('head'); + $this->element('title', null, $this->successShortTitle()); + $this->elementEnd('head'); + $this->elementStart('body'); + $form = $this->successNextForm(); + $form->show(); + $this->elementEnd('body'); + $this->endHTML(); + } else { + $url = common_local_url('pluginsadminpanel'); + common_redirect($url, 303); + } + } + /** * Value to save into $config['plugins']['disable-'] */ diff --git a/lib/admin/pluginlist.php b/lib/admin/pluginlist.php index 5918c8ebde..ab94240378 100644 --- a/lib/admin/pluginlist.php +++ b/lib/admin/pluginlist.php @@ -177,7 +177,8 @@ class PluginList extends Widget $internal_plugin_name = self::internalizePluginName($info['name']); // For a proper comparison, we do it in lower case - if (strtolower($internal_plugin_name) == strtolower($plugin)) { + //if (strtolower($internal_plugin_name) == strtolower($plugin)) { + if ($internal_plugin_name == $plugin) { return true; } } diff --git a/lib/util/gnusocial.php b/lib/util/gnusocial.php index 7bf083d9f9..176b59d331 100644 --- a/lib/util/gnusocial.php +++ b/lib/util/gnusocial.php @@ -42,7 +42,7 @@ class GNUsocial */ public static function addModule(string $name, array $attrs = []) { - $name = ucfirst($name); + //$name = ucfirst($name); if (isset(self::$modules[$name])) { // We have already loaded this module. Don't try to @@ -93,12 +93,17 @@ class GNUsocial * @param string $name class name & module file/subdir name * @param array $attrs key/value pairs of public attributes to set on module instance * - * @return bool + * @return bool true if now enabled, false if just loaded * @throws ServerException if module can't be found */ public static function addPlugin(string $name, array $attrs = []) { - $name = ucfirst($name); + //$name = ucfirst($name); + + $key = 'disable-' . $name; + if (common_config('plugins', $key)) { + return false; + } if (isset(self::$modules[$name])) { // We have already loaded this module. Don't try to @@ -145,13 +150,14 @@ class GNUsocial public static function delPlugin($name) { + //$name = ucfirst($name); + // Remove our module if it was previously loaded - $name = ucfirst($name); if (isset(self::$modules[$name])) { unset(self::$modules[$name]); } - // make sure initPlugins will avoid this + // make sure addPlugin and addModule will avoid this common_config_set('plugins', 'disable-' . $name, true); return true; @@ -275,11 +281,6 @@ class GNUsocial // Load default plugins foreach (common_config('plugins', 'default') as $name => $params) { - $key = 'disable-' . $name; - if (common_config('plugins', $key)) { - continue; - } - if (count($params) == 0) { self::addPlugin($name); } else { diff --git a/plugins/OverwriteThemeBackground/OverwriteThemeBackgroundPlugin.php b/plugins/OverwriteThemeBackground/OverwriteThemeBackgroundPlugin.php index db870415aa..125e69ba67 100644 --- a/plugins/OverwriteThemeBackground/OverwriteThemeBackgroundPlugin.php +++ b/plugins/OverwriteThemeBackground/OverwriteThemeBackgroundPlugin.php @@ -61,7 +61,7 @@ class OverwriteThemeBackgroundPlugin extends Plugin public function onPluginVersion(array &$versions): bool { $versions[] = [ - 'name' => 'Custom Background', + 'name' => 'Overwrite Theme Background', 'version' => self::PLUGIN_VERSION, 'author' => 'Diogo Cordeiro', 'homepage' => 'https://www.diogo.site/projects/GNU-social/plugins/OverwriteThemeBackgroundPlugin',