BxBasePage.php 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  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. require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
  10. /**
  11. * Page representation.
  12. * @see BxDolPage
  13. */
  14. class BxBasePage extends BxDolPage
  15. {
  16. protected $_oTemplate;
  17. protected $_sStorage; //--- Storage object for page's images like custom cover, HTML block attachments, etc.
  18. protected $_oPageCacheObject = null;
  19. protected $_oBlockCacheObject = null;
  20. protected $_sJsClassName = '';
  21. protected $_sJsObjectName = '';
  22. protected $_aHtmlIds = [];
  23. protected $_bStickyColumns = false;
  24. protected $_bSubPage = false;
  25. public function __construct ($aObject, $oTemplate)
  26. {
  27. parent::__construct ($aObject);
  28. if ($oTemplate)
  29. $this->_oTemplate = $oTemplate;
  30. else
  31. $this->_oTemplate = BxDolTemplate::getInstance();
  32. $this->_sStorage = 'sys_images';
  33. $this->_sJsClassName = 'BxDolPage';
  34. $this->_sJsObjectName = 'oBxDolPage';
  35. $this->_bStickyColumns = isset($this->_aObject['sticky_columns']) && $this->_aObject['sticky_columns'] == 1;
  36. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $this->_sObject);
  37. $this->_aHtmlIds = array(
  38. 'help_popup' => $sHtmlId . '-help-popup-',
  39. );
  40. $this->addMarkers(array('site_title' => getParam('site_title')));
  41. }
  42. public function performActionGetHelp ()
  43. {
  44. $iBlockId = (int)bx_get('block_id');
  45. if(empty($iBlockId))
  46. return;
  47. $aBlock = $this->_oQuery->getPageBlock($iBlockId);
  48. if(empty($aBlock) || !is_array($aBlock) || empty($aBlock['help']))
  49. return;
  50. echo $this->_oTemplate->parseHtmlByName('designbox_help_popup.html', array(
  51. 'content' => _t($aBlock['help'])
  52. ));
  53. }
  54. public function performActionGetShare ()
  55. {
  56. $aEmbedData = BxDolPage::getEmbedData(bx_get('url'));
  57. if(!isset($aEmbedData['url']))
  58. return;
  59. $sMenu = '';
  60. if(getParam('sys_a2a_enable') != 'on') {
  61. if(($oMenu = BxDolMenu::getObjectInstance('sys_social_sharing')) !== false) {
  62. $oMenu->addMarkers([
  63. 'url' => $aEmbedData['url'],
  64. 'img_url_encoded' => '',
  65. 'title_encoded' => ''
  66. ]);
  67. $sMenu = $oMenu->getCode();
  68. }
  69. }
  70. else
  71. $sMenu = getParam('sys_a2a_code');
  72. echo PopupBox('sys_share_popup', _t('_sys_txt_share_popup_header'), $this->_oTemplate->parseHtmlByName('designbox_share_popup.html', [
  73. 'url' => bx_process_output($aEmbedData['url']),
  74. 'menu' => $sMenu,
  75. 'code' => htmlspecialchars($aEmbedData['html']),
  76. ]), true);
  77. }
  78. public function performActionEmbed ()
  79. {
  80. $aCover = $this->getPageCoverImage();
  81. $sTitle = $this->_getPageTitle();
  82. $this->_oTemplate->getEmbed($this->_oTemplate->parseHtmlByName('embed_card.html', [
  83. 'title' => $sTitle,
  84. 'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
  85. 'bx_if:thumb' => [
  86. 'condition' => $this->isPageCover() && count($aCover) > 0,
  87. 'content' => [
  88. 'title' => $sTitle,
  89. 'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
  90. 'background' => BxDolCover::getInstance(BxDolTemplate::getInstance())->getCoverImageUrl($aCover)
  91. ],
  92. ],
  93. 'bx_if:no_thumb' => [
  94. 'condition' => count($aCover) == 0 || !$this->isPageCover(),
  95. 'content' => [
  96. 'title' => $sTitle,
  97. 'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
  98. ]
  99. ]
  100. ]
  101. ));
  102. }
  103. public function performActionCreativeSave()
  104. {
  105. if(!$this->isAllowedCreativeManage())
  106. return echoJson(['code' => 1]);
  107. $iId = 0;
  108. $sContent = '';
  109. if(($iId = bx_get('b')) === false || ($sContent = bx_get('c')) === false)
  110. return echoJson(['code' => 2]);
  111. $iId = bx_process_input($iId, BX_DATA_INT);
  112. $sContent = bx_process_input($sContent, BX_DATA_HTML);
  113. if(!$this->_oQuery->setPageBlockContent($iId, $sContent))
  114. return echoJson(['code' => 3]);
  115. return echoJson(['code' => 0]);
  116. }
  117. public function isAllowedCreativeManage()
  118. {
  119. return isAdmin();
  120. }
  121. /**
  122. * Very similar to BxBasePage::getCode
  123. * but adds css and js files which are needed for the corect page display
  124. */
  125. public function getCodeDynamic ()
  126. {
  127. // TODO: remake to use use collect* template methods
  128. $oTemplate = BxDolTemplate::getInstance();
  129. // get js&css before the page code is generated
  130. $aCssBefore = $oTemplate->getCss();
  131. $aJsBefore = $oTemplate->getJs();
  132. // generate page code
  133. $sContent = $this->getCode();
  134. // get js&css after the page code is generated
  135. $aCssAfter = $oTemplate->getCss();
  136. $aJsAfter = $oTemplate->getJs();
  137. // compare files which were added before and after page code is generated
  138. $f = function ($a1, $a2) {
  139. return strcasecmp($a1['url'], $a2['url']);
  140. };
  141. $aCssNew = array_udiff($aCssAfter, $aCssBefore, $f);
  142. $aJsNew = array_udiff($aJsAfter, $aJsBefore, $f);
  143. // add newly added js&css files in static mode
  144. $sCss = $sJs = '';
  145. foreach ($aCssNew as $a)
  146. $sCss .= $oTemplate->addCss($a['url'], true);
  147. foreach ($aJsNew as $a)
  148. $sJs .= $oTemplate->addJs($a['url'], true);
  149. return $sJs . $sCss . $sContent;
  150. }
  151. public function getIncludes ()
  152. {
  153. $oTemplate = BxDolTemplate::getInstance();
  154. // generate page code
  155. $this->getCode();
  156. // get js&css after the page code is generated
  157. $aCss = $oTemplate->getCss();
  158. $aJs = $oTemplate->getJs();
  159. // add js&css files in static mode
  160. $sResult = '';
  161. foreach ($aCss as $a)
  162. $sResult .= $oTemplate->addCss($a['url'], true);
  163. foreach ($aJs as $a)
  164. $sResult .= $oTemplate->addJs($a['url'], true);
  165. // add js translations
  166. $sResult .= $oTemplate->getJsTranslation(true);
  167. return $sResult;
  168. }
  169. /**
  170. * Get page code with automatic caching, adding necessary css/js files and system template vars.
  171. * @return string.
  172. */
  173. public function getCode ()
  174. {
  175. if (bx_get('dynamic') && ($iBlockId = (int)bx_get('pageBlock'))) {
  176. if (self::isLockedFromUnauthenticated($this->_aObject['uri']) || !$this->_isVisiblePage($this->_aObject)) {
  177. header('HTTP/1.0 403 Forbidden');
  178. exit;
  179. }
  180. /**
  181. * @hooks
  182. * @hookdef hook-system-page_output_block 'system', 'page_output_block' - hook with page block data to be output
  183. * - $unit_name - equals `system`
  184. * - $action - equals `page_output_block`
  185. * - $object_id - not used
  186. * - $sender_id - not used
  187. * - $extra_params - array of additional params with the following array keys:
  188. * - `page_name` - [string] page object name
  189. * - `page_object` - [object] an instance of page class, @see BxDolPage
  190. * - `page_query` - [object] an instance of page related query class
  191. * - `block_id` - [int] block id
  192. * @hook @ref hook-system-page_output_block
  193. */
  194. bx_alert('system', 'page_output_block', 0, false, [
  195. 'page_name' => $this->_sObject,
  196. 'page_object' => $this,
  197. 'page_query' => $this->_oQuery,
  198. 'block_id' => (int)$iBlockId,
  199. ]);
  200. header( 'Content-type:text/html;charset=utf-8' );
  201. BxDolTemplate::getInstance()->collectingStart();
  202. $s = $this->_getBlockOnlyCode($iBlockId);
  203. $sCss = bx_get('includedCss');
  204. $sJs = bx_get('includedJs');
  205. echo BxDolTemplate::getInstance()->collectingEndGetCode($sCss ? @json_decode($sCss) : [], $sJs ? @json_decode($sJs) : []);
  206. echo $s;
  207. exit;
  208. }
  209. if (($mixedAvailable = $this->_isAvailablePage($this->_aObject)) !== true)
  210. return $this->_getPageNotFoundMsg($mixedAvailable);
  211. if (($mixedVisible = $this->_isVisiblePage($this->_aObject)) !== true)
  212. return $this->_getPageAccessDeniedMsg($mixedVisible);
  213. $this->_addJsCss();
  214. if (!$this->_bSubPage) {
  215. $this->_addSysTemplateVars();
  216. $this->_selectMenu();
  217. $this->_setSubmenu(array());
  218. }
  219. if (bx_is_dbg() || !getParam('sys_page_cache_enable') || !$this->_aObject['cache_lifetime'] || (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST')) {
  220. $sPageCode = $this->_getPageCode();
  221. }
  222. else {
  223. $oCache = $this->_getPageCacheObject();
  224. $sKey = $this->_getPageCacheKey();
  225. $sKeyCssJs = 'cssjs_' . $sKey;
  226. $mixedRet = $oCache->getData($sKey, $this->_aObject['cache_lifetime']);
  227. $aRetCssJs = $oCache->getData($sKeyCssJs, $this->_aObject['cache_lifetime']);
  228. if ($mixedRet !== null && $aRetCssJs !== null) {
  229. BxDolTemplate::getInstance()->collectingStart();
  230. BxDolTemplate::getInstance()->collectingInject($aRetCssJs['css'], $aRetCssJs['js']);
  231. $sPageCode = BxDolTemplate::getInstance()->collectingEndGetCode();
  232. $sPageCode .= $mixedRet;
  233. } else {
  234. BxDolTemplate::getInstance()->collectingStart();
  235. $sPageCode = $this->_getPageCode();
  236. $aPageCssJs = BxDolTemplate::getInstance()->collectingEndGetCode(array(), array(), 'array');
  237. $oCache->setData($sKey, $sPageCode, $this->_aObject['cache_lifetime']);
  238. $oCache->setData($sKeyCssJs, $aPageCssJs, $this->_aObject['cache_lifetime']);
  239. }
  240. }
  241. /**
  242. * @hooks
  243. * @hookdef hook-system-page_output 'system', 'page_output' - hook with page data to be output
  244. * - $unit_name - equals `system`
  245. * - $action - equals `page_output`
  246. * - $object_id - not used
  247. * - $sender_id - not used
  248. * - $extra_params - array of additional params with the following array keys:
  249. * - `page_name` - [string] page object name
  250. * - `page_object` - [object] an instance of page class, @see BxDolPage
  251. * - `page_query` - [object] an instance of page related query class
  252. * - `page_code` - [string] by ref, final page code to be output, can be overridden in hook processing
  253. * - `sub_page` - [boolean] if the page is used as subpage of some parent page
  254. * @hook @ref hook-system-page_output
  255. */
  256. bx_alert('system', 'page_output', 0, false, [
  257. 'page_name' => $this->_sObject,
  258. 'page_object' => $this,
  259. 'page_query' => $this->_oQuery,
  260. 'page_code' => &$sPageCode,
  261. 'sub_page' => $this->_bSubPage,
  262. ]);
  263. if (!$this->_bSubPage)
  264. $sPageCode .= $this->getJsScript();
  265. return $sPageCode;
  266. }
  267. public function getJsClassName()
  268. {
  269. return $this->_sJsClassName;
  270. }
  271. public function getJsObjectName()
  272. {
  273. return $this->_sJsObjectName;
  274. }
  275. function _wrapInTagJsCode($sCode)
  276. {
  277. return "<script language=\"javascript\">\n<!--\n" . $sCode . "\n-->\n</script>";
  278. }
  279. public function getJsScript()
  280. {
  281. $sJsObjName = $this->getJsObjectName();
  282. $sJsObjClass = $this->getJsClassName();
  283. $sCode = "if(window['" . $sJsObjName . "'] == undefined) var " . $sJsObjName . " = new " . $sJsObjClass . "(" . json_encode(array(
  284. 'sObjName' => $sJsObjName,
  285. 'sObject' => $this->_sObject,
  286. 'sRootUrl' => BX_DOL_URL_ROOT,
  287. 'aHtmlIds' => $this->_aHtmlIds,
  288. 'isStickyColumns' => $this->_bStickyColumns
  289. )) . ");";
  290. return $this->_wrapInTagJsCode($sCode);
  291. }
  292. /**
  293. * Is page cover enabled.
  294. * @return string
  295. */
  296. public function isPageCover()
  297. {
  298. $bResult = false;
  299. switch((int)$this->_aObject['cover']) {
  300. case 1: //--- Enabled for all
  301. $bResult = true;
  302. break;
  303. case 2: //--- Enabled for visitors only
  304. $bResult = !isLogged();
  305. break;
  306. case 3: //--- Enabled for members only
  307. $bResult = isLogged();
  308. break;
  309. }
  310. return $bResult;
  311. }
  312. public function setSubPage($b = true)
  313. {
  314. $this->_bSubPage = $b;
  315. }
  316. public function setPageCover($bCover = true)
  317. {
  318. $this->_aObject['cover'] = (bool)$bCover;
  319. }
  320. public function getPageCoverImage($bTranscoder = true)
  321. {
  322. $iId = (int)$this->_aObject['cover_image'];
  323. if(empty($iId)) {
  324. $iId = (int)getParam('sys_site_cover_common');
  325. if(empty($iId))
  326. return array();
  327. }
  328. $aResult = array(
  329. 'id' => $iId
  330. );
  331. if($bTranscoder)
  332. $aResult['transcoder'] = BX_DOL_TRANSCODER_OBJ_COVER;
  333. else
  334. $aResult['object'] = $this->_sStorage;
  335. return $aResult;
  336. }
  337. public function getPageCoverParams()
  338. {
  339. $aParams = [
  340. 'title' => $this->_getPageTitle(),
  341. 'actions' => '',
  342. 'bx_if:image' => [
  343. 'condition' => false,
  344. 'content' => []
  345. ],
  346. 'bx_if:icon' => [
  347. 'condition' => false,
  348. 'content' => []
  349. ],
  350. ];
  351. if(($oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu')) !== false) {
  352. $aCoverParams = $oMenuSubmenu->getPageCoverParams();
  353. if(!empty($aCoverParams) && is_array($aCoverParams))
  354. $aParams = $aCoverParams;
  355. }
  356. if(!empty($this->_aObject['cover_title'])) {
  357. $sCoverTitle = _t($this->_aObject['cover_title']);
  358. if($sCoverTitle && strcmp($sCoverTitle, $this->_aObject['cover_title']) != 0)
  359. $aParams['title'] = $sCoverTitle;
  360. }
  361. return $aParams;
  362. }
  363. /**
  364. * Get block title.
  365. * @return string
  366. */
  367. public function getBlockTitle ($aBlock)
  368. {
  369. return $this->_replaceMarkers(_t($aBlock['title']), array('block_id' => $aBlock['id']));
  370. }
  371. /**
  372. * Get help control if help is available for the block.
  373. * @return string
  374. */
  375. public function getBlockHelp ($aBlock)
  376. {
  377. if(empty($aBlock['help']) || empty(strip_tags(_t($aBlock['help']))))
  378. return '';
  379. return $this->_oTemplate->parseHtmlByName('designbox_help.html', array(
  380. 'js_object' => $this->_sJsObjectName,
  381. 'block_id' => $aBlock['id']
  382. ));
  383. }
  384. /**
  385. * Get code to load block asyncroniously
  386. * @param $aBlock block code
  387. * @param $iAsync if greater than 0 the it defines loading indicator for the block
  388. * @return HTML code string
  389. */
  390. public function getBlockAsyncCode($aBlock, $iAsync)
  391. {
  392. $aContentPlaceholder = $this->_oQuery->getPageBlockContentPlaceholder($iAsync);
  393. if (!$aContentPlaceholder)
  394. return _t('_sys_txt_error_occured');
  395. $oTemplate = $this->_oTemplate;
  396. if ('system' != $aContentPlaceholder['module']) {
  397. $oModule = BxDolModule::getInstance($aContentPlaceholder['module']);
  398. if (!$oModule)
  399. return _t('_sys_txt_error_occured');
  400. $oTemplate = $oModule->_oTemplate;
  401. }
  402. return $oTemplate->parseHtmlByName($aContentPlaceholder['template'], $aBlock);
  403. }
  404. /**
  405. * Get page array with all cells and blocks
  406. */
  407. public function getPageAPI ($aBlocks = [])
  408. {
  409. define('BX_API_PAGE', true);
  410. $query_string = '';
  411. if (isset(bx_get('params')[2]) && bx_get('params')[2] != ''){
  412. $array = json_decode(bx_get('params')[2], true);
  413. $query_string = http_build_query($array);
  414. parse_str($query_string, $a);
  415. $_GET = array_merge($_GET, $a);
  416. }
  417. $bIsAvailable = $this->_isAvailablePage($this->_aObject);
  418. $bIsVisible = $this->_isVisiblePage($this->_aObject);
  419. //TODO: If page isn't Available or isn't Visible then we should exit with related Error Codes immediately.
  420. $sMetaTitle = $this->_getPageMetaTitle();
  421. $sName = $this->_getPageTitle();
  422. $a = [
  423. 'id' => $this->_aObject['id'],
  424. 'title' => $sMetaTitle ? $sMetaTitle : $sName,
  425. 'name' => $sName,
  426. 'uri' => $this->_aObject['uri'],
  427. 'url' => ((bx_get('params')[0] ? bx_get('params')[0] : $this->_aObject['uri'] ) . ($query_string != '' ? '?' . $query_string : '')),
  428. 'author' => $this->_aObject['author'],
  429. 'added' => $this->_aObject['added'],
  430. 'module' => $this->getModule(),
  431. 'type' => $this->getType (),
  432. 'layout' => str_replace('.html', '', $this->_aObject['template']),
  433. 'cover_block' => '',
  434. 'menu_top' => '',
  435. 'menu' => '',
  436. 'menu_bottom' => '',
  437. 'menu_add' => '',
  438. 'elements' => $this->getPageBlocksAPI($aBlocks),
  439. ];
  440. $sMenuTop = getParam('sys_api_menu_top');
  441. if (!empty($sMenuTop) && ($oMenuTop = BxDolMenu::getObjectInstance($sMenuTop)) !== false)
  442. $a['menu_top'] = $oMenuTop->getCodeAPI();
  443. if (($oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu')) !== false) {
  444. if(($sSubmenu = $this->getSubMenu()) !== '')
  445. $oMenuSubmenu->setObjectSubmenu($sSubmenu, []);
  446. $a['menu'] = $oMenuSubmenu->getCodeAPI();
  447. }
  448. /**
  449. * Profile/Context view page.
  450. */
  451. if(isset($this->_aProfileInfo)) {
  452. $oProfileModule = BxDolModule::getInstance($this->_aProfileInfo['type']);
  453. if($oProfileModule !== null)
  454. $aProfileContentInfo = $oProfileModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  455. if(!empty($aProfileContentInfo) && is_array($aProfileContentInfo)) {
  456. $CNF = &$oProfileModule->_oConfig->CNF;
  457. /**
  458. * Process page cover with related menus and lists.
  459. */
  460. if(BxDolCover::getInstance($this)->isCover()) {
  461. $a['cover_block'] = [
  462. 'profile' => BxDolProfile::getData($this->_aProfileInfo['id'], [
  463. 'get_avatar' => 'getAvatarBig',
  464. 'with_info' => true
  465. ]),
  466. 'actions_menu' => '',
  467. 'meta_menu' => '',
  468. 'badges' => BxDolProfile::getInstance($this->_aProfileInfo['id'])->getBadges(),
  469. 'cover' => $oProfileModule->serviceGetCover($this->_aProfileInfo['content_id']),
  470. 'allow_edit' => $oProfileModule->checkAllowedChangeCover($aProfileContentInfo) === CHECK_ACTION_RESULT_ALLOWED
  471. ];
  472. if(!empty($CNF['OBJECT_MENU_VIEW_ENTRY_META']) && ($oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META'])) !== false)
  473. $a['cover_block']['meta_menu'] = $oMetaMenu->getCodeAPI();
  474. if(!empty($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) !== false)
  475. $a['cover_block']['members_list'] = $oConnection->getConnectedListAPI($this->_aProfileInfo['id'], false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 10);
  476. if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']) && ($oActionMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'])) !== false)
  477. $a['cover_block']['actions_menu'] = $oActionMenu->getCodeAPI();
  478. }
  479. /**
  480. * Process page mange menu.
  481. */
  482. if(($oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage')) !== false) {
  483. if(!empty($CNF['FIELD_ID']))
  484. $oMenuManage->setContentId($aProfileContentInfo[$CNF['FIELD_ID']]);
  485. $aObjectManage = [];
  486. if(!empty($CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']))
  487. $aObjectManage = [$CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']];
  488. else if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  489. $aObjectManage = [$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE'], true];
  490. call_user_func_array([$oMenuManage, 'setObjectManage'], $aObjectManage);
  491. $aMenuManage = $oMenuManage->getCodeAPI();
  492. if(!empty($aMenuManage) && is_array($aMenuManage)) {
  493. if(isset($a['cover_block'], $a['cover_block']['actions_menu']) && is_array($a['cover_block']['actions_menu']))
  494. $a['cover_block']['actions_menu']['items'] = array_merge($a['cover_block']['actions_menu']['items'], $aMenuManage['items']);
  495. else
  496. $a['cover_block']['actions_menu'] = $aMenuManage;
  497. }
  498. }
  499. }
  500. }
  501. if (isLogged()) {
  502. $o = BxDolProfile::getInstance();
  503. $a['user'] = BxDolProfile::getDataForPage($o);
  504. }
  505. $aExtras = [
  506. 'page' => $this,
  507. 'blocks' => $aBlocks,
  508. 'data' => &$a,
  509. ];
  510. if(!$bIsAvailable)
  511. $a['page_status'] = 404;
  512. else if(!$bIsVisible)
  513. $a['page_status'] = 403;
  514. /**
  515. * @hooks
  516. * @hookdef hook-system-get_page_api 'system', 'get_page_api' - hook to override page peremeters, is used in API calls
  517. * - $unit_name - equals `system`
  518. * - $action - equals `get_page_api`
  519. * - $object_id - not used
  520. * - $sender_id - not used
  521. * - $extra_params - array of additional params with the following array keys:
  522. * - `page` - [object] an instance of page class, @see BxDolPage
  523. * - `blocks` - [array] array with page blocks
  524. * - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
  525. * @hook @ref hook-system-get_page_api
  526. */
  527. bx_alert('system', 'get_page_api', 0, 0, $aExtras);
  528. return $a;
  529. }
  530. public function getPageBlocksAPI($aBlocks = [])
  531. {
  532. $bBlocks = !empty($aBlocks) && is_array($aBlocks);
  533. $aFieldsUnset = ['object', 'cell_id', 'title_system', 'class', 'submenu', 'tabs', 'async', 'visible_for_levels', 'hidden_on', 'type', 'text', 'text_updated', 'help', 'cache_lifetime', 'active', 'active_api', 'copyable', 'deletable', 'order'];
  534. $aCells = $this->_oQuery->getPageBlocks(true);
  535. foreach($aCells as $sKey => &$aCell) {
  536. foreach($aCell as $i => $aBlock) {
  537. if(!$this->_isVisibleBlock($aBlock)) {
  538. unset($aCells[$sKey][$i]);
  539. continue;
  540. }
  541. $this->processPageBlock($aCells[$sKey][$i], true);
  542. $aBlock = $aCells[$sKey][$i];
  543. $sSource = '';
  544. if($aBlock['type'] == 'service') {
  545. $aContent = @unserialize($aBlock['content']);
  546. if(isset($aContent['module'], $aContent['method']))
  547. $sSource = $aContent['module'] . ':' . $aContent['method'];
  548. }
  549. else{
  550. $sSource = 'system:block_' . $aBlock['id'];
  551. }
  552. if($bBlocks && !in_array($sSource, $aBlocks)) {
  553. unset($aCells[$sKey][$i]);
  554. continue;
  555. }
  556. $sFunc = '_getBlock' . bx_gen_method_name($aBlock['type']);
  557. $mBlock = method_exists($this, $sFunc) ? $this->$sFunc($aBlock) : $aBlock['content'];
  558. $aCells[$sKey][$i] = array_merge($aCells[$sKey][$i], [
  559. 'title' => isset($mBlock['title']) ? $mBlock['title'] : $this->getBlockTitle($aBlock),
  560. 'content' => isset($mBlock['content']) ? $mBlock['content'] : $mBlock,
  561. 'menu' => isset($mBlock['menu']) ? $mBlock['menu'] : '',
  562. 'source' => $sSource
  563. ]);
  564. $aCells[$sKey][$i] = array_diff_key($aCells[$sKey][$i], array_flip($aFieldsUnset));
  565. }
  566. }
  567. return array_map('array_values', $aCells);
  568. }
  569. /**
  570. * Get page code vars
  571. * @return string
  572. */
  573. protected function _getPageCodeVars ()
  574. {
  575. $aHiddenOn = array(
  576. pow(2, BX_DB_HIDDEN_PHONE - 1) => 'bx-def-media-phone-hide',
  577. pow(2, BX_DB_HIDDEN_TABLET - 1) => 'bx-def-media-tablet-hide',
  578. pow(2, BX_DB_HIDDEN_DESKTOP - 1) => 'bx-def-media-desktop-hide',
  579. pow(2, BX_DB_HIDDEN_MOBILE - 1) => 'bx-def-mobile-app-hide'
  580. );
  581. $aVars = array (
  582. 'page_id' => 'bx-page-' . $this->_aObject['uri'],
  583. 'bx_if:show_layout_row_dump' => array(
  584. 'condition' => false,
  585. 'content' => array()
  586. )
  587. );
  588. $aBlocks = $this->_oQuery->getPageBlocks();
  589. foreach ($aBlocks as $sKey => $aCell) {
  590. $sCell = '';
  591. foreach ($aCell as $aBlock) {
  592. $this->processPageBlock($aBlock, false);
  593. $sContentWithBox = $this->_getBlockCodeWithCache($aBlock, $aBlock['async']);
  594. $sClassAdd = '';
  595. if(!empty($aBlock['class']))
  596. $sClassAdd .= ' ' . $aBlock['class'];
  597. if(!empty($aBlock['hidden_on']))
  598. foreach($aHiddenOn as $iHiddenOn => $sHiddenOnClass)
  599. if((int)$aBlock['hidden_on'] & $iHiddenOn)
  600. $sClassAdd .= ' ' . $sHiddenOnClass;
  601. if ($sContentWithBox)
  602. $sCell .= $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
  603. 'class_add' => $sClassAdd,
  604. 'bx_if:show_html_id' => array(
  605. 'condition' => true,
  606. 'content' => array(
  607. 'html_id' => 'bx-page-block-' . $aBlock['id']
  608. ),
  609. ),
  610. 'content' => $sContentWithBox
  611. ));
  612. }
  613. $aVars[$sKey] = $sCell;
  614. }
  615. return $aVars;
  616. }
  617. /**
  618. * Process block values, especially if someting need to be overrided
  619. */
  620. protected function processPageBlock(&$aBlock, $bApi = false)
  621. {
  622. }
  623. /**
  624. * Get page code only.
  625. * @return string
  626. */
  627. protected function _getPageCode ()
  628. {
  629. $aVars = $this->_getPageCodeVars ();
  630. return $this->_oTemplate->parseHtmlByName($this->_aObject['template'], $aVars);
  631. }
  632. /**
  633. * Get one block code only.
  634. * @return string
  635. */
  636. protected function _getBlockOnlyCode ($iBlockId)
  637. {
  638. if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
  639. return '';
  640. return $this->_getBlockCodeWithCache($aBlock, 0);
  641. }
  642. protected function _getBlockCodeWithCache(&$aBlock, $iAsync = 0)
  643. {
  644. if (bx_is_dbg() || !getParam('sys_pb_cache_enable') || !$aBlock['cache_lifetime'] || $iAsync || (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST')) {
  645. $sBlockCode = $this->_getBlockCode($aBlock, $iAsync);
  646. }
  647. else {
  648. $oCache = $this->_getBlockCacheObject();
  649. $sKey = $this->_getBlockCacheKey(false, $aBlock);
  650. $sKeyCssJs = 'cssjs_' . $sKey;
  651. $mixedRet = $oCache->getData($sKey, $aBlock['cache_lifetime']);
  652. $aRetCssJs = $oCache->getData($sKeyCssJs, $aBlock['cache_lifetime']);
  653. if ($mixedRet !== null && $aRetCssJs !== null) {
  654. BxDolTemplate::getInstance()->collectingStart();
  655. BxDolTemplate::getInstance()->collectingInject($aRetCssJs['css'], $aRetCssJs['js']);
  656. $sBlockCode = BxDolTemplate::getInstance()->collectingEndGetCode();
  657. $sBlockCode .= $mixedRet;
  658. } else {
  659. BxDolTemplate::getInstance()->collectingStart();
  660. $sBlockCode = $this->_getBlockCode($aBlock, $iAsync);
  661. $aBlockCssJs = BxDolTemplate::getInstance()->collectingEndGetCode(array(), array(), 'array');
  662. $oCache->setData($sKey, $sBlockCode, $aBlock['cache_lifetime']);
  663. $oCache->setData($sKeyCssJs, $aBlockCssJs, $aBlock['cache_lifetime']);
  664. }
  665. }
  666. return $sBlockCode;
  667. }
  668. /**
  669. * Get block code.
  670. * @return string
  671. */
  672. protected function _getBlockCode(&$aBlock, $iAsync = 0)
  673. {
  674. $sContentWithBox = '';
  675. $oFunctions = $this->_oTemplate->getTemplateFunctions();
  676. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPageBlock(_t($aBlock['title']), $aBlock['id']);
  677. $aDbNoTitle = [BX_DB_CONTENT_ONLY, BX_DB_PADDING_CONTENT_ONLY, BX_DB_NO_CAPTION, BX_DB_PADDING_NO_CAPTION];
  678. $sTitle = $this->getBlockTitle($aBlock);
  679. $sHelp = $this->getBlockHelp($aBlock);
  680. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  681. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  682. if ($iAsync && $bBlockVisible) {
  683. $iDesignboxId = $aBlock['designbox_id'];
  684. $sHelpTitle = $sHelpContent = '';
  685. if(!in_array($iDesignboxId, $aDbNoTitle))
  686. $sHelpTitle = $sHelp;
  687. else
  688. $sHelpContent = $sHelp;
  689. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  690. $aParams = array(
  691. $sTitle . $sHelpTitle,
  692. $sContent . $sHelpContent,
  693. $iDesignboxId
  694. );
  695. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  696. }
  697. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  698. $mixedContent = $this->$sFunc($aBlock);
  699. if(!empty($aBlock['content_empty'])) {
  700. $sEmpty = _t($aBlock['content_empty']);
  701. $sRegExp = '/(<[A-Za-z0-9]+\b.[^<]*[\pPi\pPf]bx\-msg\-box\b.*[\pPi\pPf][^>]*>)(' . _t('_Empty') . ')(<\/[A-Za-z0-9]+>)/su';
  702. if(is_string($mixedContent))
  703. $mixedContent = preg_replace($sRegExp, "\${1}" . $sEmpty . "\${3}", $mixedContent);
  704. else if(is_array($mixedContent) && !empty($mixedContent['content']))
  705. $mixedContent['content'] = preg_replace($sRegExp, "\${1}" . $sEmpty . "\${3}", $mixedContent['content']);
  706. }
  707. $this->_oQuery->setReadOnlyMode(true);
  708. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  709. $iDesignboxId = isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id'];
  710. if(!empty($mixedContent['markers']) && is_array($mixedContent['markers'])) {
  711. $this->addMarkers($mixedContent['markers']);
  712. $sTitle = $this->getBlockTitle($aBlock);
  713. }
  714. $sHelpTitle = $sHelpContent = '';
  715. if(!in_array($iDesignboxId, $aDbNoTitle))
  716. $sHelpTitle = $sHelp;
  717. else
  718. $sHelpContent = $sHelp;
  719. $aParams = array(
  720. (isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle) . $sHelpTitle,
  721. $mixedContent['content'] . $sHelpContent,
  722. $iDesignboxId
  723. );
  724. $mixedMenu = false;
  725. if(isset($mixedContent['menu']))
  726. $mixedMenu = $mixedContent['menu'];
  727. else if(!empty($aBlock['submenu']))
  728. $mixedMenu = $aBlock['submenu'];
  729. $aParams[] = $mixedMenu;
  730. if(isset($mixedContent['buttons']))
  731. $aParams[] = $mixedContent['buttons'];
  732. else if($mixedMenu)
  733. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  734. if(isset($mixedContent['class']))
  735. $aBlock['class'] = $mixedContent['class'];
  736. }
  737. else if(is_string($mixedContent) && !empty($mixedContent)) {
  738. $iDesignboxId = $aBlock['designbox_id'];
  739. $sHelpTitle = $sHelpContent = '';
  740. if(!in_array($iDesignboxId, $aDbNoTitle))
  741. $sHelpTitle = $sHelp;
  742. else
  743. $sHelpContent = $sHelp;
  744. $aParams = array(
  745. $sTitle . $sHelpTitle,
  746. $mixedContent . $sHelpContent,
  747. $iDesignboxId
  748. );
  749. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  750. $aParams[] = $mixedMenu;
  751. if($mixedMenu)
  752. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  753. }
  754. if(!empty($aParams))
  755. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  756. }
  757. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  758. return $sContentWithBox;
  759. }
  760. /**
  761. * Add necessary js and css files.
  762. */
  763. protected function _addJsCss()
  764. {
  765. $this->_oTemplate->addJs(array('BxDolPage.js', 'theia-sticky-sidebar/theia-sticky-sidebar.min.js', 'theia-sticky-sidebar/ResizeSensor.min.js'));
  766. $this->_oTemplate->addCss('page_layouts.css');
  767. }
  768. /**
  769. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  770. */
  771. protected function _addSysTemplateVars ()
  772. {
  773. $oTemplate = BxDolTemplate::getInstance();
  774. $sPageTitle = $this->_getPageTitle();
  775. if ($sPageTitle)
  776. $oTemplate->setPageHeader ($sPageTitle);
  777. $sMetaTitle = $this->_getPageMetaTitle();
  778. if ($sMetaTitle)
  779. $oTemplate->setPageMetaTitle ($sMetaTitle);
  780. $sMetaDesc = $this->_getPageMetaDesc();
  781. if ($sMetaDesc)
  782. $oTemplate->setPageDescription ($sMetaDesc);
  783. $sMetaRobots = $this->_getPageMetaRobots();
  784. if ($sMetaRobots)
  785. $oTemplate->setPageMetaRobots ($sMetaRobots);
  786. $sMetaImage = $this->_getPageMetaImage();
  787. if ($sMetaImage)
  788. $oTemplate->addPageMetaImage($sMetaImage);
  789. $sMetaKeywords = $this->_getPageMetaKeywords();
  790. if ($sMetaKeywords)
  791. $oTemplate->addPageKeywords ($sMetaKeywords);
  792. }
  793. /**
  794. * Select menu from page properties.
  795. */
  796. protected function _selectMenu ()
  797. {
  798. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  799. }
  800. /**
  801. * Set page submenu if it's specified
  802. */
  803. protected function _setSubmenu ($aParams)
  804. {
  805. if(empty($this->_aObject['submenu']) || $this->_aObject['submenu'] == 'disabled')
  806. return;
  807. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  808. if(!$oMenuSubmenu)
  809. return;
  810. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  811. }
  812. /**
  813. * Get content for 'raw' block type.
  814. * @return string
  815. */
  816. protected function _getBlockRaw ($aBlock)
  817. {
  818. if (bx_is_api()){
  819. return [bx_api_get_block('raw', ['title' => _t($aBlock['title']), 'content' => BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array())])];
  820. }
  821. $s = '<div class="bx-page-raw-container bx-def-vanilla-html max-w-none">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  822. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  823. $s = bx_process_macros($s);
  824. return $s;
  825. }
  826. /**
  827. * Get content for 'custom' block type.
  828. * @return string
  829. */
  830. protected function _getBlockCustom ($aBlock)
  831. {
  832. if (bx_is_api()){
  833. return [bx_api_get_block('custom', ['title' => _t($aBlock['title']), 'content' => BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array())])];
  834. }
  835. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  836. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  837. $s = bx_process_macros($s);
  838. return $s;
  839. }
  840. /**
  841. * Get content for 'html' block type.
  842. * @return string
  843. */
  844. protected function _getBlockHtml ($aBlock)
  845. {
  846. if (bx_is_api()){
  847. return [bx_api_get_block('html', ['title' => _t($aBlock['title']), 'content' => $aBlock['content']])];
  848. }
  849. $s = '<div class="bx-page-html-container bx-def-vanilla-html max-w-none">' . $aBlock['content'] . '</div>';
  850. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  851. $s = bx_process_macros($s);
  852. return $s;
  853. }
  854. /**
  855. * Get content for 'creative' block type.
  856. * @return string
  857. */
  858. protected function _getBlockCreative ($aBlock)
  859. {
  860. if(bx_is_api())
  861. return [bx_api_get_block('creative', ['title' => _t($aBlock['title']), 'content' => $aBlock['content']])];
  862. $s = $this->_replaceMarkers($aBlock['content'], ['block_id' => $aBlock['id']]);
  863. $s = bx_process_macros($s);
  864. $bCanManage = $this->isAllowedCreativeManage();
  865. if($bCanManage) {
  866. $this->_oTemplate->addCss([
  867. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css',
  868. ]);
  869. $this->_oTemplate->addJs([
  870. 'grapesjs/grapes.min.js',
  871. 'grapesjs/grapesjs-blocks-basic.js',
  872. 'grapesjs/grapesjs-style-bg.js',
  873. 'grapesjs/grapesjs-preset-webpage.min.js',
  874. ]);
  875. }
  876. return $this->_oTemplate->parseHtmlByName('block_creative.html', [
  877. 'block_id' => $aBlock['id'],
  878. 'content' => $s,
  879. 'bx_if:show_controls' => [
  880. 'condition' => $bCanManage,
  881. 'content' => [
  882. 'onclick_edit' => $this->_sJsObjectName . '.creativeEdit(this, ' . $aBlock['id'] . ')',
  883. 'onclick_save' => $this->_sJsObjectName . '.creativeSave(this, ' . $aBlock['id'] . ')'
  884. ]
  885. ]
  886. ]);
  887. }
  888. /**
  889. * Get content for 'bento_grid' block type.
  890. * @return string
  891. */
  892. protected function _getBlockBentoGrid ($aBlock)
  893. {
  894. if(bx_is_api()) {
  895. $iBlockId = (int)$aBlock['id'];
  896. $iContentId = 0;
  897. if(($mContentId = bx_get('id')) !== false)
  898. $iContentId = (int)$mContentId;
  899. $sContentModule = '';
  900. if(!empty($this->_aObject['module']) && !in_array($this->_aObject['module'], ['system', 'custom']))
  901. $sContentModule = $this->_aObject['module'];
  902. $bIsAllowedEdit = false;
  903. if(!empty($sContentModule) && bx_is_srv($sContentModule, 'check_allowed_with_content'))
  904. $bIsAllowedEdit = bx_srv($sContentModule, 'check_allowed_with_content', ['edit', $iContentId]) === CHECK_ACTION_RESULT_ALLOWED;
  905. else
  906. $bIsAllowedEdit = isAdmin();
  907. return [bx_api_get_block('bento_grid', [
  908. 'title' => _t($aBlock['title']),
  909. 'content' => self::getPageBlockData($iBlockId, $iContentId, $sContentModule)
  910. ], ['ext' => [
  911. 'block_id' => $iBlockId,
  912. 'content_id' => $iContentId,
  913. 'content_module' => $sContentModule,
  914. 'is_allowed_edit' => $bIsAllowedEdit
  915. ]])];
  916. }
  917. /**
  918. * Isn't supported for now.
  919. */
  920. return '';
  921. }
  922. /**
  923. * Get content for 'wiki' block type.
  924. * @return string
  925. */
  926. protected function _getBlockWiki ($aBlock)
  927. {
  928. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  929. if (!$oWiki) {
  930. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  931. }
  932. else {
  933. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  934. }
  935. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container markdown-body bx-def-vanilla-html">' . $sContent . '</div>';
  936. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  937. $s = bx_process_macros($s);
  938. return $s;
  939. }
  940. /**
  941. * Get content for 'lang' block type.
  942. * @return string
  943. */
  944. protected function _getBlockLang ($aBlock)
  945. {
  946. if (bx_is_api()){
  947. return [bx_api_get_block('lang', ['title' => _t($aBlock['title']), 'content' => bx_process_macros(_t(trim($aBlock['content'])))])];
  948. }
  949. $s = '<div class="bx-page-lang-container bx-def-vanilla-html max-w-none">' . _t(trim($aBlock['content'])) . '</div>';
  950. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  951. $s = bx_process_macros($s);
  952. return $s;
  953. }
  954. /**
  955. * Get content for 'image' block type.
  956. * @return string
  957. */
  958. protected function _getBlockImage ($aBlock)
  959. {
  960. if (empty($aBlock['content']))
  961. return false;
  962. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  963. $iFileId = (int)$iFileId;
  964. if (!$iFileId)
  965. return false;
  966. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  967. if (!$oStorage)
  968. return false;
  969. $sUrl = $oStorage->getFileUrlById($iFileId);
  970. if (!$sUrl)
  971. return false;
  972. $sStyleAdd = '';
  973. $sClassAdd = 'bx-page-image-container';
  974. $aAlign = ['left' => 'start', 'center' => 'center', 'right' => 'end'];
  975. if(array_key_exists($sAlign, $aAlign)) {
  976. $sClassAdd .= ' flex justify-' . $aAlign[$sAlign];
  977. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  978. }
  979. return '<div class="' . $sClassAdd . '" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  980. }
  981. /**
  982. * Get content for 'rss' block type.
  983. * @return string
  984. */
  985. protected function _getBlockRss ($aBlock)
  986. {
  987. if (empty($aBlock['content']))
  988. return false;
  989. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  990. $iNum = (int)$iNum;
  991. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  992. }
  993. /**
  994. * Get content for 'menu' block type.
  995. * @return string
  996. */
  997. protected function _getBlockMenu ($aBlock)
  998. {
  999. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  1000. return $oMenu ? $oMenu->getCode () : '';
  1001. }
  1002. /**
  1003. * Get content for 'service' block type.
  1004. * @return string
  1005. */
  1006. protected function _getBlockService ($aBlock)
  1007. {
  1008. $aMarkers = array_merge($this->_aMarkers, [
  1009. 'block_id' => $aBlock['id']
  1010. ]);
  1011. return BxDolService::callSerialized($aBlock['content'], $aMarkers);
  1012. }
  1013. /**
  1014. * Get page title.
  1015. * @return string
  1016. */
  1017. protected function _getPageTitle()
  1018. {
  1019. return $this->_replaceMarkers(_t($this->_aObject['title']));
  1020. }
  1021. /**
  1022. * Get page meta description.
  1023. * @return string
  1024. */
  1025. protected function _getPageMetaDesc()
  1026. {
  1027. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  1028. }
  1029. /**
  1030. * Get page meta title.
  1031. * @return string
  1032. */
  1033. protected function _getPageMetaTitle()
  1034. {
  1035. return $this->_replaceMarkers(_t($this->_aObject['meta_title']));
  1036. }
  1037. /**
  1038. * Get page meta image.
  1039. * @return string
  1040. */
  1041. protected function _getPageMetaImage()
  1042. {
  1043. return '';
  1044. }
  1045. /**
  1046. * Get page meta keywords.
  1047. * @return string
  1048. */
  1049. protected function _getPageMetaKeywords()
  1050. {
  1051. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  1052. }
  1053. /**
  1054. * Get page meta robots.
  1055. * @return string
  1056. */
  1057. protected function _getPageMetaRobots()
  1058. {
  1059. return _t($this->_aObject['meta_robots']);
  1060. }
  1061. /**
  1062. * Get page not found message.
  1063. * @return string
  1064. */
  1065. protected function _getPageNotFoundMsg ($mixedMsg = false)
  1066. {
  1067. $this->_oTemplate->displayPageNotFound();
  1068. exit;
  1069. }
  1070. /**
  1071. * Get access denied message.
  1072. * @return string
  1073. */
  1074. protected function _getPageAccessDeniedMsg ($mixedMsg = false)
  1075. {
  1076. return MsgBox($mixedMsg !== false ? $mixedMsg : _t('_Access denied'));
  1077. }
  1078. /**
  1079. * Get page cache object.
  1080. * @return cache object instance
  1081. */
  1082. protected function _getPageCacheObject ()
  1083. {
  1084. return $this->_getCacheObject ();
  1085. }
  1086. /**
  1087. * Get block cache object.
  1088. * @return cache object instance
  1089. */
  1090. protected function _getBlockCacheObject ()
  1091. {
  1092. return $this->_getCacheObject ('Block', 'pb');
  1093. }
  1094. protected function _getCacheObject ($sSuffixObj = 'Page', $sSuffixParam = 'page')
  1095. {
  1096. $sObj = '_o' . $sSuffixObj . 'CacheObject';
  1097. $sParam = 'sys_' . $sSuffixParam . '_cache_engine';
  1098. if ($this->{$sObj} != null) {
  1099. return $this->{$sObj};
  1100. } else {
  1101. $sEngine = getParam($sParam);
  1102. $this->{$sObj} = bx_instance ('BxDolCache' . $sEngine);
  1103. if (!$this->{$sObj}->isAvailable())
  1104. $this->{$sObj} = bx_instance ('BxDolCacheFile');
  1105. return $this->{$sObj};
  1106. }
  1107. }
  1108. /**
  1109. * Get page cache key.
  1110. * @param $isPrefixOnly return key prefix only.
  1111. * @return string
  1112. */
  1113. protected function _getPageCacheKey ($isPrefixOnly = false)
  1114. {
  1115. $s = 'page_' . $this->_aObject['object'] . '_';
  1116. if ($isPrefixOnly)
  1117. return $s;
  1118. $s .= $this->_getPageCacheParams ();
  1119. $s .= bx_site_hash() . '.php';
  1120. return $s;
  1121. }
  1122. /**
  1123. * Get block cache key.
  1124. * @param $isPrefixOnly return key prefix only.
  1125. * @return string
  1126. */
  1127. protected function _getBlockCacheKey ($isPrefixOnly = false, $aBlock = array())
  1128. {
  1129. $s = $this->_getPageCacheKey(true) . 'block_';
  1130. if ($isPrefixOnly)
  1131. return $s;
  1132. $s .= ($aBlock ? $aBlock['id'] : 0) . '_' . $this->_getPageCacheParams ();
  1133. $s .= bx_site_hash() . '.php';
  1134. return $s;
  1135. }
  1136. /**
  1137. * Additional cache key. In the case of dynamic page.
  1138. * For example - profile page, where each profile has own page.
  1139. * @return string
  1140. */
  1141. protected function _getPageCacheParams ()
  1142. {
  1143. return md5(serialize($_GET) . bx_lang_name());
  1144. }
  1145. /**
  1146. * Clean page cache.
  1147. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  1148. * @return string
  1149. */
  1150. protected function cleanCache ($isDelAllWithPagePrefix = false)
  1151. {
  1152. $a = ['Page', 'Block'];
  1153. $bRet = false;
  1154. foreach ($a as $s) {
  1155. $oCache = $this->{'_get' . $s . 'CacheObject'} ();
  1156. $sKey = $this->{'_get'. $s . 'CacheKey'} ($isDelAllWithPagePrefix);
  1157. if ($isDelAllWithPagePrefix)
  1158. $bRet = $bRet && $oCache->removeAllByPrefix($sKey);
  1159. else
  1160. $bRet = $bRet && $oCache->delData($sKey);
  1161. }
  1162. return $bRet;
  1163. }
  1164. }
  1165. /** @} */