| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- /**
- * System service for pages functionality.
- */
- class BxBaseServicePages extends BxDol
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * @page service Service Calls
- * @section bx_system_pages System Services
- * @subsection bx_system_pages-pages Pages
- * @subsubsection bx_system_pages-get_page_by_request Get page by page URI
- *
- * @code bx_srv('system', 'get_page_by_request', ['about'], 'TemplServicePages'); @endcode
- * @code {{~system:get_page_by_request:TemplServicePages['about']~}} @endcode
- *
- * Test method which page data
- * @param $sURI page URI
- *
- * @see BxBaseServicePages::serviceGetPage
- */
- /**
- * @ref bx_system_general-get_page_by_request "get_page_by_request"
- */
- public function serviceGetPageByRequest ($sRequest, $sBlocks = '', $sParams = '')
- {
- list($aRes, $aExtras) = $this->_getByRequest('page', $sRequest, $sBlocks, $sParams);
- if(isset($aRes['code'], $aRes['data']) && (int)$aRes['code'] == 404 && isLogged())
- $aRes['data']['user'] = BxDolProfile::getDataForPage();
-
- $aExtras['data'] = &$aRes;
- /**
- * @hooks
- * @hookdef hook-system-get_page_api 'system', 'get_page_api' - hook to override page peremeters, is used in API calls
- * - $unit_name - equals `system`
- * - $action - equals `get_page_api`
- * - $object_id - not used
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `page` - [object] an instance of page class, @see BxDolPage
- * - `blocks` - [array] array with page blocks
- * - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
- * @hook @ref hook-system-get_page_api
- */
- bx_alert('system', 'get_page_api', 0, 0, $aExtras);
- return $aRes;
- }
- public function serviceGetPageContentByRequest ($sRequest, $sBlocks = '', $sParams = '')
- {
- list($aRes, $aExtras) = $this->_getByRequest('page_content', $sRequest, $sBlocks, $sParams);
- $aExtras['data'] = &$aRes;
- /**
- * @hooks
- * @hookdef hook-system-get_page_api 'system', 'get_page_content_api' - hook to override page content, is used in API calls
- * - $unit_name - equals `system`
- * - $action - equals `get_page_content_api`
- * - $object_id - not used
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `page` - [object] an instance of page class, @see BxDolPage
- * - `blocks` - [array] array with page blocks
- * - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
- * @hook @ref hook-system-get_page_content_api
- */
- bx_alert('system', 'get_page_content_api', 0, 0, $aExtras);
- return $aRes;
- }
- /**
- * @page service Service Calls
- * @section bx_system_pages System Services
- * @subsection bx_system_pages-pages Pages
- * @subsubsection bx_system_pages-get_page_by_uri Get page by page URI
- *
- * @code bx_srv('system', 'get_page_by_uri', ['about'], 'TemplServicePages'); @endcode
- * @code {{~system:get_page_by_uri:TemplServicePages['about']~}} @endcode
- *
- * Test method which page data
- * @param $sURI page URI
- *
- * @see BxBaseServicePages::serviceGetPage
- */
- /**
- * @ref bx_system_general-get_page_by_uri "get_page_by_uri"
- */
- public function serviceGetPageByUri ($sURI)
- {
- $oPage = BxDolPage::getObjectInstanceByURI($sURI, false, true);
- if (!$oPage) {
- $aRes = ['error' => _t("_sys_request_page_not_found_cpt")];
- }
- else {
- $aRes = $oPage->getPage();
- }
- return $aRes;
- }
- public function serviceGetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
- {
- return BxDolPage::getPageBlockData($iBlockId, $iContentId, $sContentModule);
- }
- public function serviceSetPageBlockData($iBlockId, $iContentId = 0, $sContentModule = '')
- {
- $sData = @file_get_contents("php://input");
- $aData = json_decode($sData, true);
- if($aData === null)
- return false;
- return BxDolPage::setPageBlockData($iBlockId, $iContentId, $sContentModule, $sData);
- }
- public function serviceGetUrlInfo($sUrl)
- {
- $oEmbed = BxDolEmbed::getObjectInstance('sys_system');
- return $oEmbed->getData($sUrl, '');
- }
- protected function _getByRequest($sType, $sRequest, $sBlocks = '', $sParams = '')
- {
- $mixed = null;
- if (substr_count($sRequest, 'page/')> 0){
- $_GET['i'] = str_replace('page/', '', $sRequest);
- $aParams = json_decode($sParams, true);
- if(!empty($aParams) && is_array($aParams))
- $_GET = array_merge($_GET, $aParams);
-
- $mixed = BxDolPage::getObjectInstanceByURI();
- }
- else{
- if(!empty($sParams)) {
- $aParams = json_decode($sParams, true);
- if(!empty($aParams) && is_array($aParams))
- $_GET = array_merge($_GET, $aParams);
- }
- $mixed = BxDolPage::getPageBySeoLink($sRequest);
- }
- $aExtras = [
- 'request' => $sRequest,
- ];
- if(($sUrl = $mixed) && is_string($sUrl)) {
- $aResult = ['redirect' => $sUrl];
- $aExtras = array_merge($aExtras, [
- 'url' => $sUrl
- ]);
- }
- else if(($oPage = $mixed) && is_object($oPage)) {
- $aBlocks = [];
- if(!empty($sBlocks))
- $aBlocks = explode(',', $sBlocks);
- $aResult = $oPage->{'get' . bx_gen_method_name($sType) . 'API'}($aBlocks);
- $aExtras = array_merge($aExtras, [
- 'page' => $oPage,
- 'blocks' => $aBlocks
- ]);
- }
- else
- $aResult = [
- 'code' => 404,
- 'error' => _t("_sys_request_page_not_found_cpt"),
- 'data' => [
- 'page_status' => 404
- ]
- ];
- return [$aResult, $aExtras];
- }
- }
- /** @} */
|