1
0

BxBaseServicePages.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. public function serviceGetPageContentByRequest ($sRequest, $sBlocks = '', $sParams = '')
  95. {
  96. $mixed = null;
  97. if (substr_count($sRequest, 'page/')> 0){
  98. $_GET['i'] = str_replace('page/', '', $sRequest);
  99. $aParams = json_decode($sParams, true);
  100. if(!empty($aParams) && is_array($aParams))
  101. $_GET = array_merge($_GET, $aParams);
  102. $mixed = BxDolPage::getObjectInstanceByURI();
  103. }
  104. else{
  105. if(!empty($sParams)) {
  106. $aParams = json_decode($sParams, true);
  107. if(!empty($aParams) && is_array($aParams))
  108. $_GET = array_merge($_GET, $aParams);
  109. }
  110. $mixed = BxDolPage::getPageBySeoLink($sRequest);
  111. }
  112. $aExtras = [
  113. 'request' => $sRequest,
  114. ];
  115. if (($sUrl = $mixed) && is_string($sUrl)) {
  116. $aRes = ['redirect' => $sUrl];
  117. $aExtras = array_merge($aExtras, [
  118. 'url' => $sUrl
  119. ]);
  120. }
  121. elseif (($oPage = $mixed) && is_object($oPage)) {
  122. $aBlocks = [];
  123. if(!empty($sBlocks))
  124. $aBlocks = explode(',', $sBlocks);
  125. $aRes = $oPage->getPageContentAPI($aBlocks);
  126. $aExtras = array_merge($aExtras, [
  127. 'page' => $oPage,
  128. 'blocks' => $aBlocks
  129. ]);
  130. }
  131. else {
  132. $aRes = ['code' => 404, 'error' => _t("_sys_request_page_not_found_cpt"), 'data' => ['page_status' => 404]];
  133. }
  134. $aExtras['data'] = &$aRes;
  135. /**
  136. * @hooks
  137. * @hookdef hook-system-get_page_api 'system', 'get_page_content_api' - hook to override page content, is used in API calls
  138. * - $unit_name - equals `system`
  139. * - $action - equals `get_page_content_api`
  140. * - $object_id - not used
  141. * - $sender_id - not used
  142. * - $extra_params - array of additional params with the following array keys:
  143. * - `page` - [object] an instance of page class, @see BxDolPage
  144. * - `blocks` - [array] array with page blocks
  145. * - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
  146. * @hook @ref hook-system-get_page_content_api
  147. */
  148. bx_alert('system', 'get_page_content_api', 0, 0, $aExtras);
  149. return $aRes;
  150. }
  151. /**
  152. * @page service Service Calls
  153. * @section bx_system_pages System Services
  154. * @subsection bx_system_pages-pages Pages
  155. * @subsubsection bx_system_pages-get_page_by_uri Get page by page URI
  156. *
  157. * @code bx_srv('system', 'get_page_by_uri', ['about'], 'TemplServicePages'); @endcode
  158. * @code {{~system:get_page_by_uri:TemplServicePages['about']~}} @endcode
  159. *
  160. * Test method which page data
  161. * @param $sURI page URI
  162. *
  163. * @see BxBaseServicePages::serviceGetPage
  164. */
  165. /**
  166. * @ref bx_system_general-get_page_by_uri "get_page_by_uri"
  167. */
  168. public function serviceGetPageByUri ($sURI)
  169. {
  170. $oPage = BxDolPage::getObjectInstanceByURI($sURI, false, true);
  171. if (!$oPage) {
  172. $aRes = ['error' => _t("_sys_request_page_not_found_cpt")];
  173. }
  174. else {
  175. $aRes = $oPage->getPage();
  176. }
  177. return $aRes;
  178. }
  179. public function serviceGetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
  180. {
  181. return BxDolPage::getPageBlockData($iBlockId, $iContentId, $sContentModule);
  182. }
  183. public function serviceSetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
  184. {
  185. $sData = @file_get_contents("php://input");
  186. $aData = json_decode($sData, true);
  187. if($aData === null)
  188. return false;
  189. return BxDolPage::setPageBlockData($iBlockId, $iContentId, $sContentModule, $sData);
  190. }
  191. public function serviceGetUrlInfo($sUrl)
  192. {
  193. $oEmbed = BxDolEmbed::getObjectInstance('sys_system');
  194. return $oEmbed->getData($sUrl, '');
  195. }
  196. }
  197. /** @} */