[MODULES] Make disable in admin panel effective
This commit is contained in:
parent
16b5ddd230
commit
ee405df000
@ -38,6 +38,52 @@ defined('STATUSNET') || die();
|
|||||||
*/
|
*/
|
||||||
class PlugindisableAction extends PluginenableAction
|
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-<name>']
|
* Value to save into $config['plugins']['disable-<name>']
|
||||||
*/
|
*/
|
||||||
|
@ -177,7 +177,8 @@ class PluginList extends Widget
|
|||||||
$internal_plugin_name = self::internalizePluginName($info['name']);
|
$internal_plugin_name = self::internalizePluginName($info['name']);
|
||||||
|
|
||||||
// For a proper comparison, we do it in lower case
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class GNUsocial
|
|||||||
*/
|
*/
|
||||||
public static function addModule(string $name, array $attrs = [])
|
public static function addModule(string $name, array $attrs = [])
|
||||||
{
|
{
|
||||||
$name = ucfirst($name);
|
//$name = ucfirst($name);
|
||||||
|
|
||||||
if (isset(self::$modules[$name])) {
|
if (isset(self::$modules[$name])) {
|
||||||
// We have already loaded this module. Don't try to
|
// 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 string $name class name & module file/subdir name
|
||||||
* @param array $attrs key/value pairs of public attributes to set on module instance
|
* @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
|
* @throws ServerException if module can't be found
|
||||||
*/
|
*/
|
||||||
public static function addPlugin(string $name, array $attrs = [])
|
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])) {
|
if (isset(self::$modules[$name])) {
|
||||||
// We have already loaded this module. Don't try to
|
// We have already loaded this module. Don't try to
|
||||||
@ -145,13 +150,14 @@ class GNUsocial
|
|||||||
|
|
||||||
public static function delPlugin($name)
|
public static function delPlugin($name)
|
||||||
{
|
{
|
||||||
|
//$name = ucfirst($name);
|
||||||
|
|
||||||
// Remove our module if it was previously loaded
|
// Remove our module if it was previously loaded
|
||||||
$name = ucfirst($name);
|
|
||||||
if (isset(self::$modules[$name])) {
|
if (isset(self::$modules[$name])) {
|
||||||
unset(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);
|
common_config_set('plugins', 'disable-' . $name, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -275,11 +281,6 @@ class GNUsocial
|
|||||||
|
|
||||||
// Load default plugins
|
// Load default plugins
|
||||||
foreach (common_config('plugins', 'default') as $name => $params) {
|
foreach (common_config('plugins', 'default') as $name => $params) {
|
||||||
$key = 'disable-' . $name;
|
|
||||||
if (common_config('plugins', $key)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($params) == 0) {
|
if (count($params) == 0) {
|
||||||
self::addPlugin($name);
|
self::addPlugin($name);
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,7 +61,7 @@ class OverwriteThemeBackgroundPlugin extends Plugin
|
|||||||
public function onPluginVersion(array &$versions): bool
|
public function onPluginVersion(array &$versions): bool
|
||||||
{
|
{
|
||||||
$versions[] = [
|
$versions[] = [
|
||||||
'name' => 'Custom Background',
|
'name' => 'Overwrite Theme Background',
|
||||||
'version' => self::PLUGIN_VERSION,
|
'version' => self::PLUGIN_VERSION,
|
||||||
'author' => 'Diogo Cordeiro',
|
'author' => 'Diogo Cordeiro',
|
||||||
'homepage' => 'https://www.diogo.site/projects/GNU-social/plugins/OverwriteThemeBackgroundPlugin',
|
'homepage' => 'https://www.diogo.site/projects/GNU-social/plugins/OverwriteThemeBackgroundPlugin',
|
||||||
|
Loading…
Reference in New Issue
Block a user