BxBasePage.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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. public function __construct ($aObject, $oTemplate)
  20. {
  21. parent::__construct ($aObject);
  22. if ($oTemplate)
  23. $this->_oTemplate = $oTemplate;
  24. else
  25. $this->_oTemplate = BxDolTemplate::getInstance();
  26. $this->_sStorage = 'sys_images';
  27. $this->_sJsClassName = 'BxDolPage';
  28. $this->_sJsObjectName = 'oBxDolPage';
  29. }
  30. /**
  31. * Very similar to BxBasePage::getCode
  32. * but adds css and js files which are needed for the corect page display
  33. */
  34. public function getCodeDynamic ()
  35. {
  36. // TODO: remake to use use collect* template methods
  37. $oTemplate = BxDolTemplate::getInstance();
  38. // get js&css before the page code is generated
  39. $aCssBefore = $oTemplate->getCss();
  40. $aJsBefore = $oTemplate->getJs();
  41. // generate page code
  42. $sContent = $this->getCode();
  43. // get js&css after the page code is generated
  44. $aCssAfter = $oTemplate->getCss();
  45. $aJsAfter = $oTemplate->getJs();
  46. // compare files which were added before and after page code is generated
  47. $f = function ($a1, $a2) {
  48. return strcasecmp($a1['url'], $a2['url']);
  49. };
  50. $aCssNew = array_udiff($aCssAfter, $aCssBefore, $f);
  51. $aJsNew = array_udiff($aJsAfter, $aJsBefore, $f);
  52. // add newly added js&css files in static mode
  53. $sCss = $sJs = '';
  54. foreach ($aCssNew as $a)
  55. $sCss .= $oTemplate->addCss($a['url'], true);
  56. foreach ($aJsNew as $a)
  57. $sJs .= $oTemplate->addJs($a['url'], true);
  58. return $sJs . $sCss . $sContent;
  59. }
  60. /**
  61. * Get page code with automatic caching, adding necessary css/js files and system template vars.
  62. * @return string.
  63. */
  64. public function getCode ()
  65. {
  66. if (bx_get('dynamic') && ($iBlockId = (int)bx_get('pageBlock'))) {
  67. if (!$this->_isVisiblePage($this->_aObject)) {
  68. header('HTTP/1.0 403 Forbidden');
  69. exit;
  70. }
  71. bx_alert('system', 'page_output_block', 0, false, array(
  72. 'page_name' => $this->_sObject,
  73. 'page_object' => $this,
  74. 'page_query' => $this->_oQuery,
  75. 'block_id' => (int)$iBlockId,
  76. ));
  77. header( 'Content-type:text/html;charset=utf-8' );
  78. BxDolTemplate::getInstance()->collectingStart();
  79. $s = $this->_getBlockOnlyCode($iBlockId);
  80. $sCss = bx_get('includedCss');
  81. $sJs = bx_get('includedJs');
  82. echo BxDolTemplate::getInstance()->collectingEndGetCode($sCss ? json_decode($sCss) : array(), $sJs ? json_decode($sJs) : array());
  83. echo $s;
  84. exit;
  85. }
  86. if (!$this->_isVisiblePage($this->_aObject))
  87. return $this->_getPageAccessDeniedMsg ();
  88. $this->_addJsCss();
  89. $this->_addSysTemplateVars();
  90. $this->_selectMenu();
  91. $this->_setSubmenu(array());
  92. if (!getParam('sys_page_cache_enable') || !$this->_aObject['cache_lifetime']) {
  93. $sPageCode = $this->_getPageCode();
  94. }
  95. else {
  96. $oCache = $this->_getPageCacheObject();
  97. $sKey = $this->_getPageCacheKey();
  98. $mixedRet = $oCache->getData($sKey, $this->_aObject['cache_lifetime']);
  99. if ($mixedRet !== null) {
  100. $sPageCode = $mixedRet;
  101. } else {
  102. $sPageCode = $this->_getPageCode();
  103. $oCache->setData($sKey, $sPageCode, $this->_aObject['cache_lifetime']);
  104. }
  105. }
  106. bx_alert('system', 'page_output', 0, false, array(
  107. 'page_name' => $this->_sObject,
  108. 'page_object' => $this,
  109. 'page_query' => $this->_oQuery,
  110. 'page_code' => &$sPageCode,
  111. ));
  112. $sPageCode .= $this->getJsScript();
  113. return $sPageCode;
  114. }
  115. public function getJsClassName()
  116. {
  117. return $this->_sJsClassName;
  118. }
  119. public function getJsObjectName()
  120. {
  121. return $this->_sJsObjectName;
  122. }
  123. function _wrapInTagJsCode($sCode)
  124. {
  125. return "<script language=\"javascript\">\n<!--\n" . $sCode . "\n-->\n</script>";
  126. }
  127. public function getJsScript()
  128. {
  129. $sJsObjName = $this->getJsObjectName();
  130. $sJsObjClass = $this->getJsClassName();
  131. $sCode = "if(window['" . $sJsObjName . "'] == undefined) var " . $sJsObjName . " = new " . $sJsObjClass . "(" . json_encode(array(
  132. 'sObjName' => $sJsObjName,
  133. 'isStickyColumns' => isset($this->_aObject['sticky_columns']) && $this->_aObject['sticky_columns'] == 1
  134. )) . ");";
  135. return $this->_wrapInTagJsCode($sCode);
  136. }
  137. /**
  138. * Is page cover enabled.
  139. * @return string
  140. */
  141. public function isPageCover()
  142. {
  143. $bResult = false;
  144. switch((int)$this->_aObject['cover']) {
  145. case 1: //--- Enabled for all
  146. $bResult = true;
  147. break;
  148. case 2: //--- Enabled for visitors only
  149. $bResult = !isLogged();
  150. break;
  151. case 3: //--- Enabled for members only
  152. $bResult = isLogged();
  153. break;
  154. }
  155. return $bResult;
  156. }
  157. public function setPageCover($bCover = true)
  158. {
  159. $this->_aObject['cover'] = (bool)$bCover;
  160. }
  161. public function getPageCoverImage($bTranscoder = true)
  162. {
  163. $iId = (int)$this->_aObject['cover_image'];
  164. if(empty($iId)) {
  165. $iId = (int)getParam('sys_site_cover_common');
  166. if(empty($iId))
  167. return array();
  168. }
  169. $aResult = array(
  170. 'id' => $iId
  171. );
  172. if($bTranscoder)
  173. $aResult['transcoder'] = BX_DOL_TRANSCODER_OBJ_COVER;
  174. else
  175. $aResult['object'] = $this->_sStorage;
  176. return $aResult;
  177. }
  178. public function getPageCoverParams()
  179. {
  180. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  181. if($oMenuSubmenu) {
  182. $aParams = $oMenuSubmenu->getPageCoverParams();
  183. if(!empty($aParams) && is_array($aParams))
  184. return $aParams;
  185. }
  186. return array (
  187. 'title' => $this->_getPageTitle(),
  188. 'actions' => '',
  189. 'bx_if:image' => array (
  190. 'condition' => false,
  191. 'content' => array(),
  192. ),
  193. 'bx_if:icon' => array (
  194. 'condition' => false,
  195. 'content' => array(),
  196. ),
  197. );
  198. }
  199. /**
  200. * Get block title.
  201. * @return string
  202. */
  203. public function getBlockTitle ($aBlock)
  204. {
  205. return $this->_replaceMarkers(_t($aBlock['title']), array('block_id' => $aBlock['id']));
  206. }
  207. /**
  208. * Get code to load block asyncroniously
  209. * @param $aBlock block code
  210. * @param $iAsync if greater than 0 the it defines loading indicator for the block
  211. * @return HTML code string
  212. */
  213. public function getBlockAsyncCode($aBlock, $iAsync)
  214. {
  215. $aContentPlaceholder = $this->_oQuery->getPageBlockContentPlaceholder($iAsync);
  216. if (!$aContentPlaceholder)
  217. return _t('_sys_txt_error_occured');
  218. $oTemplate = $this->_oTemplate;
  219. if ('system' != $aContentPlaceholder['module']) {
  220. $oModule = BxDolModule::getInstance($aContentPlaceholder['module']);
  221. if (!$oModule)
  222. return _t('_sys_txt_error_occured');
  223. $oTemplate = $oModule->_oTemplate;
  224. }
  225. return $oTemplate->parseHtmlByName($aContentPlaceholder['template'], $aBlock);
  226. }
  227. /**
  228. * Get page array with all cells and blocks
  229. */
  230. public function getPage ()
  231. {
  232. return array(
  233. 'id' => $this->_aObject['id'],
  234. 'title' => $this->_getPageTitle(),
  235. 'uri' => $this->_aObject['uri'],
  236. 'author' => $this->_aObject['author'],
  237. 'added' => $this->_aObject['added'],
  238. 'module' => $this->getModule (),
  239. 'type' => $this->getType (),
  240. 'layout' => $this->_aObject['layout_id'],
  241. 'elements' => $this->getPageBlocks (),
  242. );
  243. }
  244. public function getPageBlocks ()
  245. {
  246. $aFieldsUnset = array('cell_id', 'active', 'copyable', 'deletable', 'object', 'text', 'text_updated', 'title_system', 'visible_for_levels');
  247. $aCells = $this->_oQuery->getPageBlocks();
  248. foreach ($aCells as $sKey => $aCell) {
  249. foreach ($aCell as $i => $aBlock) {
  250. if (!$this->_isVisibleBlock($aBlock))
  251. unset($aCells[$sKey][$i]);
  252. $this->processPageBlock($aCells[$sKey][$i], true);
  253. $aBlock = $aCells[$sKey][$i];
  254. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  255. $aCells[$sKey][$i]['content'] = method_exists($this, $sFunc) ? $this->$sFunc($aBlock) : $aBlock['content'];
  256. $aCells[$sKey][$i]['title'] = $this->getBlockTitle($aBlock);
  257. foreach ($aFieldsUnset as $s)
  258. unset($aCells[$sKey][$i][$s]);
  259. }
  260. }
  261. return $aCells;
  262. }
  263. /**
  264. * Get page code vars
  265. * @return string
  266. */
  267. protected function _getPageCodeVars ()
  268. {
  269. $aHiddenOn = array(
  270. pow(2, BX_DB_HIDDEN_PHONE - 1) => 'bx-def-media-phone-hide',
  271. pow(2, BX_DB_HIDDEN_TABLET - 1) => 'bx-def-media-tablet-hide',
  272. pow(2, BX_DB_HIDDEN_DESKTOP - 1) => 'bx-def-media-desktop-hide',
  273. pow(2, BX_DB_HIDDEN_MOBILE - 1) => 'bx-def-mobile-app-hide'
  274. );
  275. $aVars = array (
  276. 'page_id' => 'bx-page-' . $this->_aObject['uri'],
  277. 'bx_if:show_layout_row_dump' => array(
  278. 'condition' => false,
  279. 'content' => array()
  280. )
  281. );
  282. $aBlocks = $this->_oQuery->getPageBlocks();
  283. foreach ($aBlocks as $sKey => $aCell) {
  284. $sCell = '';
  285. foreach ($aCell as $aBlock) {
  286. $this->processPageBlock($aBlock, false);
  287. $sContentWithBox = $this->_getBlockCode($aBlock, $aBlock['async']);
  288. $sHiddenOn = '';
  289. if(!empty($aBlock['hidden_on']))
  290. foreach($aHiddenOn as $iHiddenOn => $sClass)
  291. if((int)$aBlock['hidden_on'] & $iHiddenOn)
  292. $sHiddenOn .= ' ' . $sClass;
  293. if ($sContentWithBox)
  294. $sCell .= '<div class="bx-page-block-container bx-def-padding-sec-topbottom' . $sHiddenOn . '" id="bx-page-block-' . $aBlock['id'] . '">' . $sContentWithBox . '</div>';
  295. }
  296. $aVars[$sKey] = $sCell;
  297. }
  298. return $aVars;
  299. }
  300. /**
  301. * Process block values, especially if someting need to be overrided
  302. */
  303. protected function processPageBlock(&$aBlock, $bApi = false)
  304. {
  305. }
  306. /**
  307. * Get page code only.
  308. * @return string
  309. */
  310. protected function _getPageCode ()
  311. {
  312. $aVars = $this->_getPageCodeVars ();
  313. return $this->_oTemplate->parseHtmlByName($this->_aObject['template'], $aVars);
  314. }
  315. /**
  316. * Get one block code only.
  317. * @return string
  318. */
  319. protected function _getBlockOnlyCode ($iBlockId)
  320. {
  321. if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
  322. return '';
  323. return $this->_getBlockCode($aBlock, 0);
  324. }
  325. /**
  326. * Get block code.
  327. * @return string
  328. */
  329. protected function _getBlockCode($aBlock, $iAsync = 0)
  330. {
  331. $sContentWithBox = '';
  332. $oFunctions = $this->_oTemplate->getTemplateFunctions();
  333. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPageBlock(_t($aBlock['title']), $aBlock['id']);
  334. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  335. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  336. if ($iAsync && $bBlockVisible) {
  337. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  338. $aParams = array(
  339. $this->getBlockTitle($aBlock),
  340. $sContent,
  341. $aBlock['designbox_id']
  342. );
  343. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  344. }
  345. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  346. $mixedContent = $this->$sFunc($aBlock);
  347. $sTitle = $this->getBlockTitle($aBlock);
  348. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  349. $aParams = array(
  350. isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle,
  351. $mixedContent['content'],
  352. isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id']
  353. );
  354. $mixedMenu = false;
  355. if(isset($mixedContent['menu']))
  356. $mixedMenu = $mixedContent['menu'];
  357. else if(!empty($aBlock['submenu']))
  358. $mixedMenu = $aBlock['submenu'];
  359. $aParams[] = $mixedMenu;
  360. if(isset($mixedContent['buttons']))
  361. $aParams[] = $mixedContent['buttons'];
  362. else if($mixedMenu)
  363. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  364. }
  365. else if(is_string($mixedContent) && !empty($mixedContent)) {
  366. $aParams = array(
  367. $sTitle,
  368. $mixedContent,
  369. $aBlock['designbox_id']
  370. );
  371. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  372. $aParams[] = $mixedMenu;
  373. if($mixedMenu)
  374. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  375. }
  376. if(!empty($aParams))
  377. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  378. }
  379. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  380. return $sContentWithBox;
  381. }
  382. /**
  383. * Add necessary js and css files.
  384. */
  385. protected function _addJsCss()
  386. {
  387. $this->_oTemplate->addJs('BxDolPage.js');
  388. $this->_oTemplate->addCss('page_sticky.css');
  389. $this->_oTemplate->addCss('page_layouts.css');
  390. }
  391. /**
  392. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  393. */
  394. protected function _addSysTemplateVars ()
  395. {
  396. $oTemplate = BxDolTemplate::getInstance();
  397. $sPageTitle = $this->_getPageTitle();
  398. if ($sPageTitle)
  399. $oTemplate->setPageHeader ($sPageTitle);
  400. $sMetaDesc = $this->_getPageMetaDesc();
  401. if ($sMetaDesc)
  402. $oTemplate->setPageDescription ($sMetaDesc);
  403. $sMetaRobots = $this->_getPageMetaRobots();
  404. if ($sMetaRobots)
  405. $oTemplate->setPageMetaRobots ($sMetaRobots);
  406. $sMetaImage = $this->_getPageMetaImage();
  407. if ($sMetaImage)
  408. $oTemplate->addPageMetaImage($sMetaImage);
  409. $sMetaKeywords = $this->_getPageMetaKeywords();
  410. if ($sMetaKeywords)
  411. $oTemplate->addPageKeywords ($sMetaKeywords);
  412. }
  413. /**
  414. * Select menu from page properties.
  415. */
  416. protected function _selectMenu ()
  417. {
  418. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  419. }
  420. /**
  421. * Set page submenu if it's specified
  422. */
  423. protected function _setSubmenu ($aParams)
  424. {
  425. if(empty($this->_aObject['submenu']))
  426. return;
  427. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  428. if(!$oMenuSubmenu)
  429. return;
  430. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  431. }
  432. /**
  433. * Get content for 'raw' block type.
  434. * @return string
  435. */
  436. protected function _getBlockRaw ($aBlock)
  437. {
  438. $s = '<div class="bx-page-raw-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  439. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  440. $s = bx_process_macros($s);
  441. return $s;
  442. }
  443. /**
  444. * Get content for 'custom' block type.
  445. * @return string
  446. */
  447. protected function _getBlockCustom ($aBlock)
  448. {
  449. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  450. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  451. $s = bx_process_macros($s);
  452. return $s;
  453. }
  454. /**
  455. * Get content for 'html' block type.
  456. * @return string
  457. */
  458. protected function _getBlockHtml ($aBlock)
  459. {
  460. $s = '<div class="bx-page-html-container">' . $aBlock['content'] . '</div>';
  461. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  462. $s = bx_process_macros($s);
  463. return $s;
  464. }
  465. /**
  466. * Get content for 'wiki' block type.
  467. * @return string
  468. */
  469. protected function _getBlockWiki ($aBlock)
  470. {
  471. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  472. if (!$oWiki) {
  473. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  474. }
  475. else {
  476. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  477. }
  478. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container">' . $sContent . '</div>';
  479. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  480. $s = bx_process_macros($s);
  481. return $s;
  482. }
  483. /**
  484. * Get content for 'lang' block type.
  485. * @return string
  486. */
  487. protected function _getBlockLang ($aBlock)
  488. {
  489. $s = '<div class="bx-page-lang-container">' . _t(trim($aBlock['content'])) . '</div>';
  490. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  491. $s = bx_process_macros($s);
  492. return $s;
  493. }
  494. /**
  495. * Get content for 'image' block type.
  496. * @return string
  497. */
  498. protected function _getBlockImage ($aBlock)
  499. {
  500. if (empty($aBlock['content']))
  501. return false;
  502. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  503. $iFileId = (int)$iFileId;
  504. if (!$iFileId)
  505. return false;
  506. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  507. if (!$oStorage)
  508. return false;
  509. $sUrl = $oStorage->getFileUrlById($iFileId);
  510. if (!$sUrl)
  511. return false;
  512. $sStyleAdd = '';
  513. if ('center' == $sAlign || 'left' == $sAlign || 'right' == $sAlign)
  514. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  515. return '<div class="bx-page-image-container" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  516. }
  517. /**
  518. * Get content for 'rss' block type.
  519. * @return string
  520. */
  521. protected function _getBlockRss ($aBlock)
  522. {
  523. if (empty($aBlock['content']))
  524. return false;
  525. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  526. $iNum = (int)$iNum;
  527. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  528. }
  529. /**
  530. * Get content for 'menu' block type.
  531. * @return string
  532. */
  533. protected function _getBlockMenu ($aBlock)
  534. {
  535. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  536. return $oMenu ? $oMenu->getCode () : '';
  537. }
  538. /**
  539. * Get content for 'service' block type.
  540. * @return string
  541. */
  542. protected function _getBlockService ($aBlock)
  543. {
  544. return BxDolService::callSerialized($aBlock['content'], $this->_aMarkers);
  545. }
  546. /**
  547. * Get page title.
  548. * @return string
  549. */
  550. protected function _getPageTitle()
  551. {
  552. return $this->_replaceMarkers(_t($this->_aObject['title']));
  553. }
  554. /**
  555. * Get page meta description.
  556. * @return string
  557. */
  558. protected function _getPageMetaDesc()
  559. {
  560. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  561. }
  562. /**
  563. * Get page meta image.
  564. * @return string
  565. */
  566. protected function _getPageMetaImage()
  567. {
  568. return '';
  569. }
  570. /**
  571. * Get page meta keywords.
  572. * @return string
  573. */
  574. protected function _getPageMetaKeywords()
  575. {
  576. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  577. }
  578. /**
  579. * Get page meta robots.
  580. * @return string
  581. */
  582. protected function _getPageMetaRobots()
  583. {
  584. return _t($this->_aObject['meta_robots']);
  585. }
  586. /**
  587. * Get access denied message HTML.
  588. * @return string
  589. */
  590. protected function _getPageAccessDeniedMsg ()
  591. {
  592. return MsgBox(_t('_Access denied'));
  593. }
  594. /**
  595. * Get page cache object.
  596. * @return cache object instance
  597. */
  598. protected function _getPageCacheObject ()
  599. {
  600. if ($this->_oPageCacheObject != null) {
  601. return $this->_oPageCacheObject;
  602. } else {
  603. $sEngine = getParam('sys_page_cache_engine');
  604. $this->_oPageCacheObject = bx_instance ('BxDolCache' . $sEngine);
  605. if (!$this->_oPageCacheObject->isAvailable())
  606. $this->_oPageCacheObject = bx_instance ('BxDolCacheFile');
  607. return $this->_oPageCacheObject;
  608. }
  609. }
  610. /**
  611. * Get page cache key.
  612. * @param $isPrefixOnly return key prefix only.
  613. * @return string
  614. */
  615. protected function _getPageCacheKey ($isPrefixOnly = false)
  616. {
  617. $s = 'page_' . $this->_aObject['object'] . '_';
  618. if ($isPrefixOnly)
  619. return $s;
  620. $s .= $this->_getPageCacheParams ();
  621. $s .= bx_site_hash() . '.php';
  622. return $s;
  623. }
  624. /**
  625. * Additional cache key. In the case of dynamic page.
  626. * For example - profile page, where each profile has own page.
  627. * @return string
  628. */
  629. protected function _getPageCacheParams ()
  630. {
  631. return '';
  632. }
  633. /**
  634. * Clean page cache.
  635. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  636. * @return string
  637. */
  638. protected function cleanCache ($isDelAllWithPagePrefix = false)
  639. {
  640. $oCache = $this->_getPageCacheObject ();
  641. $sKey = $this->_getPageCacheKey($isDelAllWithPagePrefix);
  642. if ($isDelAllWithPagePrefix)
  643. return $oCache->removeAllByPrefix($sKey);
  644. else
  645. return $oCache->delData($sKey);
  646. }
  647. }
  648. /** @} */