mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-04-04 14:43:32 -04:00
Add enable / disable extension features
See https://github.com/FreshRSS/FreshRSS/issues/252
This commit is contained in:
@@ -29,12 +29,80 @@ class FreshRSS_extension_Controller extends Minz_ActionController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This action enables a disabled extension for the current user.
|
||||
*
|
||||
* System extensions can only be enabled by an administrator.
|
||||
*
|
||||
* Parameter is:
|
||||
* - e: the extension name (urlencoded).
|
||||
*/
|
||||
public function enableAction() {
|
||||
|
||||
$url_redirect = array('c' => 'extension', 'a' => 'index');
|
||||
|
||||
if (Minz_Request::isPost()) {
|
||||
$ext_name = urldecode(Minz_Request::param('e'));
|
||||
$ext = Minz_ExtensionManager::find_extension($ext_name);
|
||||
|
||||
if (is_null($ext)) {
|
||||
Minz_Request::bad('feedback.extension.not_found', $url_redirect);
|
||||
}
|
||||
|
||||
if ($ext->is_enabled()) {
|
||||
Minz_Request::bad('feedback.extension.already_enabled', $url_redirect);
|
||||
}
|
||||
|
||||
if ($ext->getType() === 'system' && !FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Request::bad('feedback.extension.no_access', $url_redirect);
|
||||
}
|
||||
|
||||
$ext->install();
|
||||
|
||||
FreshRSS_Context::$conf->addExtension($ext_name);
|
||||
FreshRSS_Context::$conf->save();
|
||||
|
||||
Minz_Request::good('feedback.extension.enabled', $url_redirect);
|
||||
}
|
||||
|
||||
Minz_Request::forward($url_redirect, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* This action disables an enabled extension for the current user.
|
||||
*
|
||||
* System extensions can only be disabled by an administrator.
|
||||
*
|
||||
* Parameter is:
|
||||
* - e: the extension name (urlencoded).
|
||||
*/
|
||||
public function disableAction() {
|
||||
|
||||
$url_redirect = array('c' => 'extension', 'a' => 'index');
|
||||
|
||||
if (Minz_Request::isPost()) {
|
||||
$ext_name = urldecode(Minz_Request::param('e'));
|
||||
$ext = Minz_ExtensionManager::find_extension($ext_name);
|
||||
|
||||
if (is_null($ext)) {
|
||||
Minz_Request::bad('feedback.extension.not_found', $url_redirect);
|
||||
}
|
||||
|
||||
if (!$ext->is_enabled()) {
|
||||
Minz_Request::bad('feedback.extension.not_enabled', $url_redirect);
|
||||
}
|
||||
|
||||
if ($ext->getType() === 'system' && !FreshRSS_Auth::hasAccess('admin')) {
|
||||
Minz_Request::bad('feedback.extension.no_access', $url_redirect);
|
||||
}
|
||||
|
||||
$ext->uninstall();
|
||||
|
||||
FreshRSS_Context::$conf->removeExtension($ext_name);
|
||||
FreshRSS_Context::$conf->save();
|
||||
|
||||
Minz_Request::good('feedback.extension.disabled', $url_redirect);
|
||||
}
|
||||
|
||||
Minz_Request::forward($url_redirect, true);
|
||||
}
|
||||
|
||||
public function removeAction() {
|
||||
|
||||
@@ -350,4 +350,16 @@ class FreshRSS_Configuration {
|
||||
}
|
||||
$this->data['extensions_enabled'] = $value;
|
||||
}
|
||||
public function removeExtension($ext_name) {
|
||||
$this->data['extensions_enabled'] = array_diff(
|
||||
$this->data['extensions_enabled'],
|
||||
array($ext_name)
|
||||
);
|
||||
}
|
||||
public function addExtension($ext_name) {
|
||||
$found = array_search($ext_name, $this->data['extensions_enabled']) !== false;
|
||||
if (!$found) {
|
||||
$this->data['extensions_enabled'][] = $ext_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,10 +160,8 @@ class Minz_ExtensionManager {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns a list of extensions.
|
||||
* Return a list of extensions.
|
||||
*
|
||||
* @param $only_enabled if true returns only the enabled extensions (false by default).
|
||||
* @return an array of extensions.
|
||||
@@ -175,4 +173,18 @@ class Minz_ExtensionManager {
|
||||
return self::$ext_list;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an extension by its name.
|
||||
*
|
||||
* @param $ext_name the name of the extension.
|
||||
* @return the corresponding extension or null if it doesn't exist.
|
||||
*/
|
||||
public static function find_extension($ext_name) {
|
||||
if (!isset(self::$ext_list[$ext_name])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::$ext_list[$ext_name];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user