plugins.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="plugins"
  5. * )
  6. */
  7. $app->get('/plugins', function ($request, $response, $args) {
  8. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  9. if ($Organizr->checkRoute($request)) {
  10. $GLOBALS['api']['response']['data'] = $Organizr->getPlugins();
  11. }
  12. $response->getBody()->write(jsonE($GLOBALS['api']));
  13. return $response
  14. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  15. ->withStatus($GLOBALS['responseCode']);
  16. });
  17. $app->get('/plugins/disabled', function ($request, $response, $args) {
  18. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  19. if ($Organizr->checkRoute($request)) {
  20. $GLOBALS['api']['response']['data'] = $Organizr->getPlugins('disabled');
  21. }
  22. $response->getBody()->write(jsonE($GLOBALS['api']));
  23. return $response
  24. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  25. ->withStatus($GLOBALS['responseCode']);
  26. });
  27. $app->get('/plugins/enabled', function ($request, $response, $args) {
  28. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  29. if ($Organizr->checkRoute($request)) {
  30. $GLOBALS['api']['response']['data'] = $Organizr->getPlugins('enabled');
  31. }
  32. $response->getBody()->write(jsonE($GLOBALS['api']));
  33. return $response
  34. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  35. ->withStatus($GLOBALS['responseCode']);
  36. });
  37. $app->post('/plugins/manage/{plugin}', function ($request, $response, $args) {
  38. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  39. if ($Organizr->qualifyRequest(1, true)) {
  40. $Organizr->installPlugin($args['plugin']);
  41. }
  42. $response->getBody()->write(jsonE($GLOBALS['api']));
  43. return $response
  44. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  45. ->withStatus($GLOBALS['responseCode']);
  46. });
  47. $app->delete('/plugins/manage/{plugin}', function ($request, $response, $args) {
  48. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  49. if ($Organizr->qualifyRequest(1, true)) {
  50. $Organizr->removePlugin($args['plugin']);
  51. }
  52. $response->getBody()->write(jsonE($GLOBALS['api']));
  53. return $response
  54. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  55. ->withStatus($GLOBALS['responseCode']);
  56. });