Parcourir la source

Enable extensions for users

Marien Fressinaud il y a 11 ans
Parent
commit
1086ba4a2b
3 fichiers modifiés avec 24 ajouts et 1 suppressions
  1. 5 1
      app/FreshRSS.php
  2. 8 0
      app/Models/Configuration.php
  3. 11 0
      lib/Minz/ExtensionManager.php

+ 5 - 1
app/FreshRSS.php

@@ -6,7 +6,7 @@ class FreshRSS extends Minz_FrontController {
 			Minz_Session::init('FreshRSS');
 		}
 
-		// Load list of extensions and initialize the "system" ones.
+		// Load list of extensions and enable the "system" ones.
 		Minz_ExtensionManager::init();
 
 		// Need to be called just after session init because it initializes
@@ -29,6 +29,10 @@ class FreshRSS extends Minz_FrontController {
 		// Load context and configuration.
 		FreshRSS_Context::init();
 
+		// Enable extensions for the current user.
+		$ext_list = FreshRSS_Context::$conf->extensions_enabled;
+		Minz_ExtensionManager::enable_by_list($ext_list);
+
 		// Init i18n.
 		Minz_Session::_param('language', FreshRSS_Context::$conf->language);
 		Minz_Translate::init();

+ 8 - 0
app/Models/Configuration.php

@@ -64,6 +64,7 @@ class FreshRSS_Configuration {
 		'sharing' => array(),
 		'queries' => array(),
 		'html5_notif_timeout' => 0,
+		'extensions_enabled' => array(),
 	);
 
 	private $available_languages = array(
@@ -342,4 +343,11 @@ class FreshRSS_Configuration {
 	public function _bottomline_link($value) {
 		$this->data['bottomline_link'] = ((bool)$value) && $value !== 'no';
 	}
+
+	public function _extensions_enabled($value) {
+		if (!is_array($value)) {
+			$value = array($value);
+		}
+		$this->data['extensions_enabled'] = $value;
+	}
 }

+ 11 - 0
lib/Minz/ExtensionManager.php

@@ -147,4 +147,15 @@ class Minz_ExtensionManager {
 			$ext->init();
 		}
 	}
+
+	/**
+	 * Enable a list of extensions.
+	 *
+	 * @param $ext_list the names of extensions we want to load.
+	 */
+	public static function enable_by_list($ext_list) {
+		foreach ($ext_list as $ext_name) {
+			self::enable($ext_name);
+		}
+	}
 }