api.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="plugins-php-mailer",
  5. * description="PHP Mailer Plugin"
  6. * )
  7. */
  8. /**
  9. * @OA\Schema(
  10. * schema="sendEmailData",
  11. * type="object",
  12. * @OA\Property(
  13. * property="bcc",
  14. * description="email of recipients (csv)",
  15. * type="string",
  16. * example="causefx@organizr.app,elmer@organizr.app",
  17. * ),
  18. * @OA\Property(
  19. * property="subject",
  20. * type="string",
  21. * example="Hey There Buddy?!",
  22. * ),
  23. * @OA\Property(
  24. * property="body",
  25. * type="string",
  26. * example="Hi! Boy, has it been a long time! Have you seen rox in socks?",
  27. * ),
  28. * )
  29. */
  30. $app->get('/plugins/php-mailer/settings', function ($request, $response, $args) {
  31. /**
  32. * @OA\Get(
  33. * tags={"plugins-php-mailer"},
  34. * path="/api/v2/plugins/php-mailer/settings",
  35. * summary="Get settings",
  36. * @OA\Response(
  37. * response="200",
  38. * description="Success",
  39. * @OA\JsonContent(ref="#/components/schemas/pluginSettingsPage"),
  40. * ),
  41. * @OA\Response(response="401",description="Unauthorized"),
  42. * security={{ "api_key":{} }}
  43. * )
  44. */
  45. $PhpMailer = new PhpMailer();
  46. if ($PhpMailer->checkRoute($request)) {
  47. if ($PhpMailer->qualifyRequest(1, true)) {
  48. $GLOBALS['api']['response']['data'] = $PhpMailer->_phpMailerPluginGetSettings();
  49. }
  50. }
  51. $response->getBody()->write(jsonE($GLOBALS['api']));
  52. return $response
  53. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  54. ->withStatus($GLOBALS['responseCode']);
  55. });
  56. $app->get('/plugins/php-mailer/email/test', function ($request, $response, $args) {
  57. /**
  58. * @OA\Get(
  59. * tags={"plugins-php-mailer"},
  60. * path="/api/v2/plugins/php-mailer/email/test",
  61. * summary="Send Test Email to Default Admin Email",
  62. * @OA\Response(
  63. * response="200",
  64. * description="Success",
  65. * @OA\JsonContent(ref="#/components/schemas/successNullData"),
  66. * ),
  67. * @OA\Response(response="401",description="Unauthorized"),
  68. * security={{ "api_key":{} }}
  69. * )
  70. */
  71. $PhpMailer = new PhpMailer();
  72. if ($PhpMailer->checkRoute($request)) {
  73. if ($PhpMailer->qualifyRequest(1, true)) {
  74. $PhpMailer->_phpMailerPluginSendTestEmail();
  75. }
  76. }
  77. $response->getBody()->write(jsonE($GLOBALS['api']));
  78. return $response
  79. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  80. ->withStatus($GLOBALS['responseCode']);
  81. });
  82. $app->post('/plugins/php-mailer/email/send', function ($request, $response, $args) {
  83. /**
  84. * @OA\Post(
  85. * tags={"plugins-php-mailer"},
  86. * path="/api/v2/plugins/php-mailer/email/send",
  87. * summary="Send Email",
  88. * @OA\RequestBody(
  89. * description="Success",
  90. * required=true,
  91. * @OA\JsonContent(ref="#/components/schemas/sendEmailData"),
  92. * ),
  93. * @OA\Response(
  94. * response="200",
  95. * description="Success",
  96. * @OA\JsonContent(ref="#/components/schemas/successNullData"),
  97. * ),
  98. * @OA\Response(response="401",description="Unauthorized"),
  99. * security={{ "api_key":{} }}
  100. * )
  101. */
  102. $PhpMailer = new PhpMailer();
  103. if ($PhpMailer->checkRoute($request)) {
  104. if ($PhpMailer->qualifyRequest(1, true)) {
  105. $PhpMailer->_phpMailerPluginAdminSendEmail($PhpMailer->apiData($request));
  106. }
  107. }
  108. $response->getBody()->write(jsonE($GLOBALS['api']));
  109. return $response
  110. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  111. ->withStatus($GLOBALS['responseCode']);
  112. });
  113. $app->get('/plugins/php-mailer/email/list', function ($request, $response, $args) {
  114. /**
  115. * @OA\Get(
  116. * tags={"plugins-php-mailer"},
  117. * path="/api/v2/plugins/php-mailer/email/list",
  118. * summary="Get List of User Emails",
  119. * @OA\Response(
  120. * response="200",
  121. * description="Success",
  122. * @OA\JsonContent(ref="#/components/schemas/php-mailer-email-list"),
  123. * ),
  124. * @OA\Response(response="401",description="Unauthorized"),
  125. * security={{ "api_key":{} }}
  126. * )
  127. */
  128. $PhpMailer = new PhpMailer();
  129. if ($PhpMailer->checkRoute($request)) {
  130. if ($PhpMailer->qualifyRequest(1, true)) {
  131. $GLOBALS['api']['response']['data'] = $PhpMailer->_phpMailerPluginGetEmails();
  132. }
  133. }
  134. $response->getBody()->write(jsonE($GLOBALS['api']));
  135. return $response
  136. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  137. ->withStatus($GLOBALS['responseCode']);
  138. });