A free, self-hostable news aggregator…
Add enable / disable extension features
Marien Fressinaud2e4682ebd451
diff --git a/app/Controllers/extensionController.php b/app/Controllers/extensionController.phpindex 504be56d3..415f489a6 100644--- a/app/Controllers/extensionController.php+++ b/app/Controllers/extensionController.php@@ -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() {diff --git a/app/Models/Configuration.php b/app/Models/Configuration.phpindex 13ce43990..83a00d4bb 100644--- a/app/Models/Configuration.php+++ b/app/Models/Configuration.php@@ -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;+ }+ }}diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.phpindex 6c32ccf19..46e421bac 100644--- a/lib/Minz/ExtensionManager.php+++ b/lib/Minz/ExtensionManager.php@@ -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];+ }}