BxBaseServicePages.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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")];
  64. }
  65. return $aRes;
  66. }
  67. /**
  68. * @page service Service Calls
  69. * @section bx_system_pages System Services
  70. * @subsection bx_system_pages-pages Pages
  71. * @subsubsection bx_system_pages-get_page_by_uri Get page by page URI
  72. *
  73. * @code bx_srv('system', 'get_page_by_uri', ['about'], 'TemplServicePages'); @endcode
  74. * @code {{~system:get_page_by_uri:TemplServicePages['about']~}} @endcode
  75. *
  76. * Test method which page data
  77. * @param $sURI page URI
  78. *
  79. * @see BxBaseServicePages::serviceGetPage
  80. */
  81. /**
  82. * @ref bx_system_general-get_page_by_uri "get_page_by_uri"
  83. */
  84. public function serviceGetPageByUri ($sURI)
  85. {
  86. $oPage = BxDolPage::getObjectInstanceByURI($sURI, false, true);
  87. if (!$oPage) {
  88. $aRes = ['error' => _t("_sys_request_page_not_found_cpt")];
  89. }
  90. else {
  91. $aRes = $oPage->getPage();
  92. }
  93. return $aRes;
  94. }
  95. }
  96. /** @} */