BxBaseServicePages.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. if (($sUrl = $mixed) && is_string($sUrl)) {
  54. $aRes = ['redirect' => $sUrl];
  55. }
  56. elseif (($oPage = $mixed) && is_object($oPage)) {
  57. $aBlocks = [];
  58. if(!empty($sBlocks))
  59. $aBlocks = explode(',', $sBlocks);
  60. return $oPage->getPageAPI($aBlocks);
  61. }
  62. else {
  63. $aRes = ['code' => 404, 'error' => _t("_sys_request_page_not_found_cpt"), 'data' => ['page_status' => 404]];
  64. if(isLogged())
  65. $aRes['data']['user'] = BxDolProfile::getDataForPage();
  66. }
  67. return $aRes;
  68. }
  69. /**
  70. * @page service Service Calls
  71. * @section bx_system_pages System Services
  72. * @subsection bx_system_pages-pages Pages
  73. * @subsubsection bx_system_pages-get_page_by_uri Get page by page URI
  74. *
  75. * @code bx_srv('system', 'get_page_by_uri', ['about'], 'TemplServicePages'); @endcode
  76. * @code {{~system:get_page_by_uri:TemplServicePages['about']~}} @endcode
  77. *
  78. * Test method which page data
  79. * @param $sURI page URI
  80. *
  81. * @see BxBaseServicePages::serviceGetPage
  82. */
  83. /**
  84. * @ref bx_system_general-get_page_by_uri "get_page_by_uri"
  85. */
  86. public function serviceGetPageByUri ($sURI)
  87. {
  88. $oPage = BxDolPage::getObjectInstanceByURI($sURI, false, true);
  89. if (!$oPage) {
  90. $aRes = ['error' => _t("_sys_request_page_not_found_cpt")];
  91. }
  92. else {
  93. $aRes = $oPage->getPage();
  94. }
  95. return $aRes;
  96. }
  97. public function serviceGetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
  98. {
  99. $oDb = new BxDolPageQuery([]);
  100. $sData = $oDb->getPageBlockData($iBlockId, $iContentId, $sContentModule);
  101. return !empty($sData) ? json_decode($sData, true) : [];
  102. }
  103. public function serviceSetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
  104. {
  105. $sData = @file_get_contents("php://input");
  106. $aData = json_decode($sData, true);
  107. if($aData === null)
  108. return false;
  109. $oDb = new BxDolPageQuery([]);
  110. return $oDb->setPageBlockData($iBlockId, $iContentId, $sContentModule, $sData);
  111. }
  112. }
  113. /** @} */