pages.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="page",
  5. * description="HTML for Organizr Pages"
  6. * )
  7. */
  8. /**
  9. * @OA\Schema(
  10. * schema="get-html",
  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 message or error message",
  24. * type="string",
  25. * example=null,
  26. * ),
  27. * @OA\Property(
  28. * property="data",
  29. * description="data from api",
  30. * type="string",
  31. * example="\r\n\u003Cscript\u003E\r\n (function() {\r\n updateCheck();\r\n authDebugCheck();\r\n sponsorLoad();\r\n newsLoad();\r\n checkCommitLoad();\r\n [].slice.call(document.querySelectorAll('.sttabs-main-settings-div')).forEach(function(el) {\r\n new CBPFWTabs(el);\r\n });\r\n })();\r\n\u003C/script\u003E\r\n"
  32. * )
  33. * ),
  34. * ),
  35. * )
  36. */
  37. $app->get('/page/{page}', function ($request, $response, $args) {
  38. /**
  39. * @OA\Get(
  40. * tags={"page"},
  41. * path="/api/v2/page/{page}",
  42. * summary="Get HTML for Organizr Pages",
  43. * @OA\Parameter(
  44. * name="page",
  45. * description="Page to get",
  46. * @OA\Schema(
  47. * type="string"
  48. * ),
  49. * in="path",
  50. * required=true
  51. * ),
  52. * @OA\Response(
  53. * response="200",
  54. * description="Success",
  55. * @OA\JsonContent(ref="#/components/schemas/get-html"),
  56. * ),
  57. * @OA\Response(response="401",description="Unauthorized"),
  58. * security={{ "api_key":{} }}
  59. * )
  60. */
  61. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  62. if ($Organizr->checkRoute($request)) {
  63. $page = $Organizr->getPage($args['page']);
  64. if ($page) {
  65. $GLOBALS['api']['response']['data'] = $page;
  66. }
  67. }
  68. $response->getBody()->write(jsonE($GLOBALS['api']));
  69. return $response
  70. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  71. ->withStatus($GLOBALS['responseCode']);
  72. });
  73. $app->get('/page', function ($request, $response, $args) {
  74. /**
  75. * @OA\Get(
  76. * tags={"page"},
  77. * path="/api/v2/page",
  78. * summary="Get list of all Organizr Pages",
  79. * @OA\Response(
  80. * response="200",
  81. * description="Success",
  82. * @OA\JsonContent(ref="#/components/schemas/get-html"),
  83. * ),
  84. * @OA\Response(response="401",description="Unauthorized"),
  85. * security={{ "api_key":{} }}
  86. * )
  87. */
  88. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  89. if ($Organizr->checkRoute($request)) {
  90. $page = $Organizr->getPageList();
  91. if ($page) {
  92. $GLOBALS['api']['response']['data'] = $page;
  93. }
  94. }
  95. $response->getBody()->write(jsonE($GLOBALS['api']));
  96. return $response
  97. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  98. ->withStatus($GLOBALS['responseCode']);
  99. });