BxApiModule.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup API API to the UNA backend
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxApiModule extends BxDolModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. public function serviceGetPublicServices()
  18. {
  19. $a = parent::serviceGetPublicServices();
  20. return array_merge($a, array (
  21. 'Test' => '',
  22. 'GetPage' => '',
  23. ));
  24. }
  25. /**
  26. * @page public_api API Public
  27. * @section public_api_api_test /m/oauth2/com/test
  28. *
  29. * Test method to check public API
  30. *
  31. * **HTTP Method:**
  32. * `GET`
  33. *
  34. * **Request params:**
  35. * n/a
  36. *
  37. * **Response (success):**
  38. * @code
  39. * {
  40. * "result": "Test passed."
  41. * }
  42. * @endcode
  43. */
  44. public function serviceTest()
  45. {
  46. return array('result' => 'Test passed.');
  47. }
  48. /**
  49. * @page public_api API Public
  50. * @section public_api_api_get_page /m/oauth2/com/get_page
  51. *
  52. * Get page with cells and blocks as array
  53. *
  54. * **HTTP Method:**
  55. * `GET`
  56. *
  57. * **Request params:**
  58. * - `uri` - page URI
  59. *
  60. * **Response (success):**
  61. * @code
  62. * {
  63. * "id": "123", // page ID
  64. * "layout": "5", // page layout, 5 is simplest page with one cell
  65. * "module": "system", // module which this page
  66. * "title": "Test page", // page title
  67. * "type": 1, // page type, 1 is for default page with header and footer
  68. * "uri": "test", // page URI, which is part of page URL
  69. * "elements": {
  70. * "cell_1": [
  71. * {
  72. * "content": "test content", // block content, it can be array as well
  73. * "designbox_id": "11", // block design, such as padding, border, title
  74. * "hidden_on": "", // not empty block need to be hidden on mobile, or desktop
  75. * "id": "321",
  76. * "module": "system", // module name this block is related to
  77. * "order": "1", // block order
  78. * "title": "Test block", // block title
  79. * "type": "raw" // block type
  80. * }
  81. * ]
  82. * }
  83. * @endcode
  84. *
  85. * **Response (error):**
  86. * @code
  87. * {
  88. * "error":"short error description here",
  89. * "error_description":"long error description here"
  90. * }
  91. * @endcode
  92. */
  93. public function serviceGetPage()
  94. {
  95. $sUri = bx_get('uri');
  96. $oPage = BxDolPage::getObjectInstanceByURI($sUri);
  97. if (!$oPage) {
  98. return array(
  99. 'code' => 404,
  100. 'error' => 'Not Found',
  101. 'desc' => 'This page doesn\'t exist',
  102. );
  103. }
  104. if (!$oPage->isVisiblePage()) {
  105. return array(
  106. 'code' => 403,
  107. 'error' => 'Forbidden',
  108. 'desc' => 'This page requires special right to be viewed',
  109. );
  110. }
  111. return $oPage->getPage ();
  112. }
  113. }
  114. /** @} */