api.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="plugins-chat",
  5. * description="Pusher Chat Plugin"
  6. * )
  7. */
  8. /**
  9. * @OA\Schema(
  10. * schema="getChatMessages",
  11. * type="object",
  12. * @OA\Property(
  13. * property="response",
  14. * type="object",
  15. * @OA\Property(
  16. * property="result",
  17. * description="success or error",
  18. * type="string",
  19. * example="success",
  20. * ),
  21. * @OA\Property(
  22. * property="message",
  23. * description="success or error message",
  24. * type="string",
  25. * example=null,
  26. * ),
  27. * @OA\Property(
  28. * property="data",
  29. * description="data from api",
  30. * type="array",
  31. * @OA\Items({
  32. * @OA\Property(
  33. * property="username",
  34. * type="string",
  35. * example="causefx",
  36. * ),
  37. * @OA\Property(
  38. * property="date",
  39. * type="string",
  40. * example="2018-09-01 02:02:24",
  41. * ),
  42. * @OA\Property(
  43. * property="gravatar",
  44. * type="string",
  45. * example="https://www.gravatar.com/avatar/a47c4a4b915ddf9601cd228f890bc366?s=100&d=mm",
  46. * ),
  47. * @OA\Property(
  48. * property="message",
  49. * type="string",
  50. * example="ok first message!",
  51. * ),
  52. * @OA\Property(
  53. * property="uid",
  54. * type="string",
  55. * example="f5287",
  56. * )
  57. * })
  58. * ),
  59. * ),
  60. * )
  61. */
  62. /**
  63. * @OA\Schema(
  64. * schema="submitMessageData",
  65. * type="object",
  66. * @OA\Property(
  67. * property="message",
  68. * type="string",
  69. * example="This is my message"
  70. * ),
  71. * )
  72. */
  73. /**
  74. * @OA\Schema(
  75. * schema="submitMessage",
  76. * type="object",
  77. * @OA\Property(
  78. * property="response",
  79. * type="object",
  80. * @OA\Property(
  81. * property="result",
  82. * description="success or error",
  83. * type="string",
  84. * example="success",
  85. * ),
  86. * @OA\Property(
  87. * property="message",
  88. * description="success or error message",
  89. * type="string",
  90. * example="message has been accepted",
  91. * ),
  92. * @OA\Property(
  93. * property="data",
  94. * description="data from api",
  95. * type="string",
  96. * example=null,
  97. * ),
  98. * ),
  99. * )
  100. */
  101. $app->get('/plugins/chat/settings', function ($request, $response, $args) {
  102. /**
  103. * @OA\Get(
  104. * tags={"plugins-chat"},
  105. * path="/api/v2/plugins/chat/settings",
  106. * summary="Get settings",
  107. * @OA\Response(
  108. * response="200",
  109. * description="Success",
  110. * @OA\JsonContent(ref="#/components/schemas/pluginSettingsPage"),
  111. * ),
  112. * @OA\Response(response="401",description="Unauthorized"),
  113. * security={{ "api_key":{} }}
  114. * )
  115. */
  116. $Chat = new Chat();
  117. if ($Chat->checkRoute($request)) {
  118. if ($Chat->qualifyRequest(1, true)) {
  119. $GLOBALS['api']['response']['data'] = $Chat->_chatPluginGetSettings();
  120. }
  121. }
  122. $response->getBody()->write(jsonE($GLOBALS['api']));
  123. return $response
  124. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  125. ->withStatus($GLOBALS['responseCode']);
  126. });
  127. $app->get('/plugins/chat/message', function ($request, $response, $args) {
  128. /**
  129. * @OA\Get(
  130. * tags={"plugins-chat"},
  131. * path="/api/v2/plugins/chat/message",
  132. * summary="Get all messages",
  133. * @OA\Response(
  134. * response="200",
  135. * description="Success",
  136. * @OA\JsonContent(ref="#/components/schemas/getChatMessages"),
  137. * ),
  138. * @OA\Response(response="401",description="Unauthorized"),
  139. * security={{ "api_key":{} }}
  140. * )
  141. */
  142. $Chat = new Chat();
  143. if ($Chat->checkRoute($request)) {
  144. if ($Chat->qualifyRequest($Chat->config['CHAT-Auth-include'], true)) {
  145. $GLOBALS['api']['response']['data'] = $Chat->_chatPluginGetChatMessages();
  146. }
  147. }
  148. $response->getBody()->write(jsonE($GLOBALS['api']));
  149. return $response
  150. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  151. ->withStatus($GLOBALS['responseCode']);
  152. });
  153. $app->post('/plugins/chat/message', function ($request, $response, $args) {
  154. /**
  155. * @OA\Post(
  156. * tags={"plugins-chat"},
  157. * path="/api/v2/plugins/chat/message",
  158. * summary="Submit a message",
  159. * @OA\RequestBody(
  160. * description="Success",
  161. * required=true,
  162. * @OA\JsonContent(ref="#/components/schemas/submitMessageData"),
  163. * @OA\MediaType(
  164. * mediaType="application/x-www-form-urlencoded",
  165. * @OA\Schema(
  166. * type="object",
  167. * @OA\Property(
  168. * property="message",
  169. * description="message to send",
  170. * type="string",
  171. * )
  172. * )
  173. * )
  174. * ),
  175. * @OA\Response(
  176. * response="200",
  177. * description="Success",
  178. * @OA\JsonContent(ref="#/components/schemas/submitMessage"),
  179. * ),
  180. * @OA\Response(response="401",description="Unauthorized"),
  181. * security={{ "api_key":{} }}
  182. * )
  183. */
  184. $Chat = new Chat();
  185. if ($Chat->checkRoute($request)) {
  186. if ($Chat->qualifyRequest($Chat->config['CHAT-Auth-include'], true)) {
  187. $Chat->_chatPluginSendChatMessage($Chat->apiData($request));
  188. }
  189. }
  190. $response->getBody()->write(jsonE($GLOBALS['api']));
  191. return $response
  192. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  193. ->withStatus($GLOBALS['responseCode']);
  194. });