浏览代码

added new plugins/enabled and plugins/disabled api endpoints
updated getPlugins function to accommodate the new api endpoints

CauseFX 4 年之前
父节点
当前提交
5abfb8c35a
共有 2 个文件被更改,包括 38 次插入2 次删除
  1. 18 2
      api/classes/organizr.class.php
  2. 20 0
      api/v2/routes/plugins.php

+ 18 - 2
api/classes/organizr.class.php

@@ -673,14 +673,30 @@ class Organizr
 		}
 	}
 	
-	public function getPlugins()
+	public function getPlugins($returnType = 'all')
 	{
 		if ($this->hasDB()) {
+			switch ($returnType) {
+				case 'enabled':
+					$returnType = 'enabled';
+					break;
+				case 'disabled':
+					$returnType = 'disabled';
+					break;
+				default:
+					$returnType = 'all';
+			}
 			$pluginList = [];
 			foreach ($GLOBALS['plugins'] as $key => $value) {
 				if (strpos($value['license'], $this->config['license']) !== false) {
 					$GLOBALS['plugins'][$key]['enabled'] = $this->config[$value['configPrefix'] . '-enabled'];
-					$pluginList[$key] = $GLOBALS['plugins'][$key];
+					if ($returnType == 'all') {
+						$pluginList[$key] = $GLOBALS['plugins'][$key];
+					} elseif ($returnType == 'enabled' && $this->config[$value['configPrefix'] . '-enabled'] == true) {
+						$pluginList[$key] = $GLOBALS['plugins'][$key];
+					} elseif ($returnType == 'disabled' && $this->config[$value['configPrefix'] . '-enabled'] == false) {
+						$pluginList[$key] = $GLOBALS['plugins'][$key];
+					}
 				}
 			}
 			asort($pluginList);

+ 20 - 0
api/v2/routes/plugins.php

@@ -14,6 +14,26 @@ $app->get('/plugins', function ($request, $response, $args) {
 		->withHeader('Content-Type', 'application/json;charset=UTF-8')
 		->withStatus($GLOBALS['responseCode']);
 });
+$app->get('/plugins/disabled', function ($request, $response, $args) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	if ($Organizr->checkRoute($request)) {
+		$GLOBALS['api']['response']['data'] = $Organizr->getPlugins('disabled');
+	}
+	$response->getBody()->write(jsonE($GLOBALS['api']));
+	return $response
+		->withHeader('Content-Type', 'application/json;charset=UTF-8')
+		->withStatus($GLOBALS['responseCode']);
+});
+$app->get('/plugins/enabled', function ($request, $response, $args) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	if ($Organizr->checkRoute($request)) {
+		$GLOBALS['api']['response']['data'] = $Organizr->getPlugins('enabled');
+	}
+	$response->getBody()->write(jsonE($GLOBALS['api']));
+	return $response
+		->withHeader('Content-Type', 'application/json;charset=UTF-8')
+		->withStatus($GLOBALS['responseCode']);
+});
 $app->post('/plugins/manage/{plugin}', function ($request, $response, $args) {
 	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
 	if ($Organizr->qualifyRequest(1, true)) {