BxBasePage.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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. $this->_oQuery->setReadOnlyMode(true);
  349. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  350. $aParams = array(
  351. isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle,
  352. $mixedContent['content'],
  353. isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id']
  354. );
  355. $mixedMenu = false;
  356. if(isset($mixedContent['menu']))
  357. $mixedMenu = $mixedContent['menu'];
  358. else if(!empty($aBlock['submenu']))
  359. $mixedMenu = $aBlock['submenu'];
  360. $aParams[] = $mixedMenu;
  361. if(isset($mixedContent['buttons']))
  362. $aParams[] = $mixedContent['buttons'];
  363. else if($mixedMenu)
  364. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  365. }
  366. else if(is_string($mixedContent) && !empty($mixedContent)) {
  367. $aParams = array(
  368. $sTitle,
  369. $mixedContent,
  370. $aBlock['designbox_id']
  371. );
  372. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  373. $aParams[] = $mixedMenu;
  374. if($mixedMenu)
  375. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  376. }
  377. if(!empty($aParams))
  378. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  379. }
  380. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  381. return $sContentWithBox;
  382. }
  383. /**
  384. * Add necessary js and css files.
  385. */
  386. protected function _addJsCss()
  387. {
  388. $this->_oTemplate->addJs('BxDolPage.js');
  389. $this->_oTemplate->addCss('page_sticky.css');
  390. $this->_oTemplate->addCss('page_layouts.css');
  391. }
  392. /**
  393. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  394. */
  395. protected function _addSysTemplateVars ()
  396. {
  397. $oTemplate = BxDolTemplate::getInstance();
  398. $sPageTitle = $this->_getPageTitle();
  399. if ($sPageTitle)
  400. $oTemplate->setPageHeader ($sPageTitle);
  401. $sMetaDesc = $this->_getPageMetaDesc();
  402. if ($sMetaDesc)
  403. $oTemplate->setPageDescription ($sMetaDesc);
  404. $sMetaRobots = $this->_getPageMetaRobots();
  405. if ($sMetaRobots)
  406. $oTemplate->setPageMetaRobots ($sMetaRobots);
  407. $sMetaImage = $this->_getPageMetaImage();
  408. if ($sMetaImage)
  409. $oTemplate->addPageMetaImage($sMetaImage);
  410. $sMetaKeywords = $this->_getPageMetaKeywords();
  411. if ($sMetaKeywords)
  412. $oTemplate->addPageKeywords ($sMetaKeywords);
  413. }
  414. /**
  415. * Select menu from page properties.
  416. */
  417. protected function _selectMenu ()
  418. {
  419. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  420. }
  421. /**
  422. * Set page submenu if it's specified
  423. */
  424. protected function _setSubmenu ($aParams)
  425. {
  426. if(empty($this->_aObject['submenu']))
  427. return;
  428. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  429. if(!$oMenuSubmenu)
  430. return;
  431. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  432. }
  433. /**
  434. * Get content for 'raw' block type.
  435. * @return string
  436. */
  437. protected function _getBlockRaw ($aBlock)
  438. {
  439. $s = '<div class="bx-page-raw-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  440. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  441. $s = bx_process_macros($s);
  442. return $s;
  443. }
  444. /**
  445. * Get content for 'custom' block type.
  446. * @return string
  447. */
  448. protected function _getBlockCustom ($aBlock)
  449. {
  450. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  451. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  452. $s = bx_process_macros($s);
  453. return $s;
  454. }
  455. /**
  456. * Get content for 'html' block type.
  457. * @return string
  458. */
  459. protected function _getBlockHtml ($aBlock)
  460. {
  461. $s = '<div class="bx-page-html-container">' . $aBlock['content'] . '</div>';
  462. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  463. $s = bx_process_macros($s);
  464. return $s;
  465. }
  466. /**
  467. * Get content for 'wiki' block type.
  468. * @return string
  469. */
  470. protected function _getBlockWiki ($aBlock)
  471. {
  472. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  473. if (!$oWiki) {
  474. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  475. }
  476. else {
  477. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  478. }
  479. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container">' . $sContent . '</div>';
  480. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  481. $s = bx_process_macros($s);
  482. return $s;
  483. }
  484. /**
  485. * Get content for 'lang' block type.
  486. * @return string
  487. */
  488. protected function _getBlockLang ($aBlock)
  489. {
  490. $s = '<div class="bx-page-lang-container">' . _t(trim($aBlock['content'])) . '</div>';
  491. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  492. $s = bx_process_macros($s);
  493. return $s;
  494. }
  495. /**
  496. * Get content for 'image' block type.
  497. * @return string
  498. */
  499. protected function _getBlockImage ($aBlock)
  500. {
  501. if (empty($aBlock['content']))
  502. return false;
  503. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  504. $iFileId = (int)$iFileId;
  505. if (!$iFileId)
  506. return false;
  507. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  508. if (!$oStorage)
  509. return false;
  510. $sUrl = $oStorage->getFileUrlById($iFileId);
  511. if (!$sUrl)
  512. return false;
  513. $sStyleAdd = '';
  514. if ('center' == $sAlign || 'left' == $sAlign || 'right' == $sAlign)
  515. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  516. return '<div class="bx-page-image-container" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  517. }
  518. /**
  519. * Get content for 'rss' block type.
  520. * @return string
  521. */
  522. protected function _getBlockRss ($aBlock)
  523. {
  524. if (empty($aBlock['content']))
  525. return false;
  526. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  527. $iNum = (int)$iNum;
  528. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  529. }
  530. /**
  531. * Get content for 'menu' block type.
  532. * @return string
  533. */
  534. protected function _getBlockMenu ($aBlock)
  535. {
  536. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  537. return $oMenu ? $oMenu->getCode () : '';
  538. }
  539. /**
  540. * Get content for 'service' block type.
  541. * @return string
  542. */
  543. protected function _getBlockService ($aBlock)
  544. {
  545. return BxDolService::callSerialized($aBlock['content'], $this->_aMarkers);
  546. }
  547. /**
  548. * Get page title.
  549. * @return string
  550. */
  551. protected function _getPageTitle()
  552. {
  553. return $this->_replaceMarkers(_t($this->_aObject['title']));
  554. }
  555. /**
  556. * Get page meta description.
  557. * @return string
  558. */
  559. protected function _getPageMetaDesc()
  560. {
  561. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  562. }
  563. /**
  564. * Get page meta image.
  565. * @return string
  566. */
  567. protected function _getPageMetaImage()
  568. {
  569. return '';
  570. }
  571. /**
  572. * Get page meta keywords.
  573. * @return string
  574. */
  575. protected function _getPageMetaKeywords()
  576. {
  577. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  578. }
  579. /**
  580. * Get page meta robots.
  581. * @return string
  582. */
  583. protected function _getPageMetaRobots()
  584. {
  585. return _t($this->_aObject['meta_robots']);
  586. }
  587. /**
  588. * Get access denied message HTML.
  589. * @return string
  590. */
  591. protected function _getPageAccessDeniedMsg ()
  592. {
  593. return MsgBox(_t('_Access denied'));
  594. }
  595. /**
  596. * Get page cache object.
  597. * @return cache object instance
  598. */
  599. protected function _getPageCacheObject ()
  600. {
  601. if ($this->_oPageCacheObject != null) {
  602. return $this->_oPageCacheObject;
  603. } else {
  604. $sEngine = getParam('sys_page_cache_engine');
  605. $this->_oPageCacheObject = bx_instance ('BxDolCache' . $sEngine);
  606. if (!$this->_oPageCacheObject->isAvailable())
  607. $this->_oPageCacheObject = bx_instance ('BxDolCacheFile');
  608. return $this->_oPageCacheObject;
  609. }
  610. }
  611. /**
  612. * Get page cache key.
  613. * @param $isPrefixOnly return key prefix only.
  614. * @return string
  615. */
  616. protected function _getPageCacheKey ($isPrefixOnly = false)
  617. {
  618. $s = 'page_' . $this->_aObject['object'] . '_';
  619. if ($isPrefixOnly)
  620. return $s;
  621. $s .= $this->_getPageCacheParams ();
  622. $s .= bx_site_hash() . '.php';
  623. return $s;
  624. }
  625. /**
  626. * Additional cache key. In the case of dynamic page.
  627. * For example - profile page, where each profile has own page.
  628. * @return string
  629. */
  630. protected function _getPageCacheParams ()
  631. {
  632. return '';
  633. }
  634. /**
  635. * Clean page cache.
  636. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  637. * @return string
  638. */
  639. protected function cleanCache ($isDelAllWithPagePrefix = false)
  640. {
  641. $oCache = $this->_getPageCacheObject ();
  642. $sKey = $this->_getPageCacheKey($isDelAllWithPagePrefix);
  643. if ($isDelAllWithPagePrefix)
  644. return $oCache->removeAllByPrefix($sKey);
  645. else
  646. return $oCache->delData($sKey);
  647. }
  648. }
  649. /** @} */