1
0

BxBaseServicePages.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System service for pages functionality.
  11. */
  12. class BxBaseServicePages extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. /**
  19. * @page service Service Calls
  20. * @section bx_system_pages System Services
  21. * @subsection bx_system_pages-pages Pages
  22. * @subsubsection bx_system_pages-get_page_by_request Get page by page URI
  23. *
  24. * @code bx_srv('system', 'get_page_by_request', ['about'], 'TemplServicePages'); @endcode
  25. * @code {{~system:get_page_by_request:TemplServicePages['about']~}} @endcode
  26. *
  27. * Test method which page data
  28. * @param $sURI page URI
  29. *
  30. * @see BxBaseServicePages::serviceGetPage
  31. */
  32. /**
  33. * @ref bx_system_general-get_page_by_request "get_page_by_request"
  34. */
  35. public function serviceGetPageByRequest ($sRequest, $sBlocks = '', $sParams = '')
  36. {
  37. $mixed = null;
  38. if (substr_count($sRequest, 'page/')> 0){
  39. $_GET['i'] = str_replace('page/', '', $sRequest);
  40. $aParams = json_decode($sParams, true);
  41. if(!empty($aParams) && is_array($aParams))
  42. $_GET = array_merge($_GET, $aParams);
  43. $mixed = BxDolPage::getObjectInstanceByURI();
  44. }
  45. else{
  46. if(!empty($sParams)) {
  47. $aParams = json_decode($sParams, true);
  48. if(!empty($aParams) && is_array($aParams))
  49. $_GET = array_merge($_GET, $aParams);
  50. }
  51. $mixed = BxDolPage::getPageBySeoLink($sRequest);
  52. }
  53. $aExtras = [
  54. 'request' => $sRequest,
  55. ];
  56. if (($sUrl = $mixed) && is_string($sUrl)) {
  57. $aRes = ['redirect' => $sUrl];
  58. $aExtras = array_merge($aExtras, [
  59. 'url' => $sUrl
  60. ]);
  61. }
  62. elseif (($oPage = $mixed) && is_object($oPage)) {
  63. $aBlocks = [];
  64. if(!empty($sBlocks))
  65. $aBlocks = explode(',', $sBlocks);
  66. $aRes = $oPage->getPageAPI($aBlocks);
  67. $aExtras = array_merge($aExtras, [
  68. 'page' => $oPage,
  69. 'blocks' => $aBlocks
  70. ]);
  71. }
  72. else {
  73. $aRes = ['code' => 404, 'error' => _t("_sys_request_page_not_found_cpt"), 'data' => ['page_status' => 404]];
  74. if(isLogged())
  75. $aRes['data']['user'] = BxDolProfile::getDataForPage();
  76. }
  77. $aExtras['data'] = &$aRes;
  78. /**
  79. * @hooks
  80. * @hookdef hook-system-get_page_api 'system', 'get_page_api' - hook to override page peremeters, is used in API calls
  81. * - $unit_name - equals `system`
  82. * - $action - equals `get_page_api`
  83. * - $object_id - not used
  84. * - $sender_id - not used
  85. * - $extra_params - array of additional params with the following array keys:
  86. * - `page` - [object] an instance of page class, @see BxDolPage
  87. * - `blocks` - [array] array with page blocks
  88. * - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
  89. * @hook @ref hook-system-get_page_api
  90. */
  91. bx_alert('system', 'get_page_api', 0, 0, $aExtras);
  92. return $aRes;
  93. }
  94. /**
  95. * @page service Service Calls
  96. * @section bx_system_pages System Services
  97. * @subsection bx_system_pages-pages Pages
  98. * @subsubsection bx_system_pages-get_page_by_uri Get page by page URI
  99. *
  100. * @code bx_srv('system', 'get_page_by_uri', ['about'], 'TemplServicePages'); @endcode
  101. * @code {{~system:get_page_by_uri:TemplServicePages['about']~}} @endcode
  102. *
  103. * Test method which page data
  104. * @param $sURI page URI
  105. *
  106. * @see BxBaseServicePages::serviceGetPage
  107. */
  108. /**
  109. * @ref bx_system_general-get_page_by_uri "get_page_by_uri"
  110. */
  111. public function serviceGetPageByUri ($sURI)
  112. {
  113. $oPage = BxDolPage::getObjectInstanceByURI($sURI, false, true);
  114. if (!$oPage) {
  115. $aRes = ['error' => _t("_sys_request_page_not_found_cpt")];
  116. }
  117. else {
  118. $aRes = $oPage->getPage();
  119. }
  120. return $aRes;
  121. }
  122. public function serviceGetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
  123. {
  124. return BxDolPage::getPageBlockData($iBlockId, $iContentId, $sContentModule);
  125. }
  126. public function serviceSetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
  127. {
  128. $sData = @file_get_contents("php://input");
  129. $aData = json_decode($sData, true);
  130. if($aData === null)
  131. return false;
  132. return BxDolPage::setPageBlockData($iBlockId, $iContentId, $sContentModule, $sData);
  133. }
  134. public function serviceGetUrlInfo($sUrl)
  135. {
  136. $oEmbed = BxDolEmbed::getObjectInstance('sys_system');
  137. return $oEmbed->getData($sUrl, '');
  138. }
  139. }
  140. /** @} */