BxBasePage.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. return $this->_oTemplate->parseHtmlByName('block_async_' . $iAsync . '.html', $aBlock);
  216. }
  217. /**
  218. * Get page array with all cells and blocks
  219. */
  220. public function getPage ()
  221. {
  222. return array(
  223. 'id' => $this->_aObject['id'],
  224. 'title' => $this->_getPageTitle(),
  225. 'uri' => $this->_aObject['uri'],
  226. 'author' => $this->_aObject['author'],
  227. 'added' => $this->_aObject['added'],
  228. 'module' => $this->getModule (),
  229. 'type' => $this->getType (),
  230. 'layout' => $this->_aObject['layout_id'],
  231. 'elements' => $this->getPageBlocks (),
  232. );
  233. }
  234. public function getPageBlocks ()
  235. {
  236. $aFieldsUnset = array('cell_id', 'active', 'copyable', 'deletable', 'object', 'text', 'text_updated', 'title_system', 'visible_for_levels');
  237. $aCells = $this->_oQuery->getPageBlocks();
  238. foreach ($aCells as $sKey => $aCell) {
  239. foreach ($aCell as $i => $aBlock) {
  240. if (!$this->_isVisibleBlock($aBlock))
  241. unset($aCells[$sKey][$i]);
  242. $this->processPageBlock($aCells[$sKey][$i], true);
  243. $aBlock = $aCells[$sKey][$i];
  244. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  245. $aCells[$sKey][$i]['content'] = method_exists($this, $sFunc) ? $this->$sFunc($aBlock) : $aBlock['content'];
  246. $aCells[$sKey][$i]['title'] = $this->getBlockTitle($aBlock);
  247. foreach ($aFieldsUnset as $s)
  248. unset($aCells[$sKey][$i][$s]);
  249. }
  250. }
  251. return $aCells;
  252. }
  253. /**
  254. * Get page code vars
  255. * @return string
  256. */
  257. protected function _getPageCodeVars ()
  258. {
  259. $aHiddenOn = array(
  260. pow(2, BX_DB_HIDDEN_PHONE - 1) => 'bx-def-media-phone-hide',
  261. pow(2, BX_DB_HIDDEN_TABLET - 1) => 'bx-def-media-tablet-hide',
  262. pow(2, BX_DB_HIDDEN_DESKTOP - 1) => 'bx-def-media-desktop-hide',
  263. pow(2, BX_DB_HIDDEN_MOBILE - 1) => 'bx-def-mobile-app-hide'
  264. );
  265. $aVars = array (
  266. 'page_id' => 'bx-page-' . $this->_aObject['uri'],
  267. 'bx_if:show_layout_row_dump' => array(
  268. 'condition' => false,
  269. 'content' => array()
  270. )
  271. );
  272. $aBlocks = $this->_oQuery->getPageBlocks();
  273. foreach ($aBlocks as $sKey => $aCell) {
  274. $sCell = '';
  275. foreach ($aCell as $aBlock) {
  276. $this->processPageBlock($aBlock, false);
  277. $sContentWithBox = $this->_getBlockCode($aBlock, $aBlock['async']);
  278. $sHiddenOn = '';
  279. if(!empty($aBlock['hidden_on']))
  280. foreach($aHiddenOn as $iHiddenOn => $sClass)
  281. if((int)$aBlock['hidden_on'] & $iHiddenOn)
  282. $sHiddenOn .= ' ' . $sClass;
  283. if ($sContentWithBox)
  284. $sCell .= '<div class="bx-page-block-container bx-def-padding-sec-topbottom' . $sHiddenOn . '" id="bx-page-block-' . $aBlock['id'] . '">' . $sContentWithBox . '</div>';
  285. }
  286. $aVars[$sKey] = $sCell;
  287. }
  288. return $aVars;
  289. }
  290. /**
  291. * Process block values, especially if someting need to be overrided
  292. */
  293. protected function processPageBlock(&$aBlock, $bApi = false)
  294. {
  295. }
  296. /**
  297. * Get page code only.
  298. * @return string
  299. */
  300. protected function _getPageCode ()
  301. {
  302. $aVars = $this->_getPageCodeVars ();
  303. return $this->_oTemplate->parseHtmlByName($this->_aObject['template'], $aVars);
  304. }
  305. /**
  306. * Get one block code only.
  307. * @return string
  308. */
  309. protected function _getBlockOnlyCode ($iBlockId)
  310. {
  311. if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
  312. return '';
  313. return $this->_getBlockCode($aBlock, 0);
  314. }
  315. /**
  316. * Get block code.
  317. * @return string
  318. */
  319. protected function _getBlockCode($aBlock, $iAsync = 0)
  320. {
  321. $sContentWithBox = '';
  322. $oFunctions = $this->_oTemplate->getTemplateFunctions();
  323. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPageBlock(_t($aBlock['title']), $aBlock['id']);
  324. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  325. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  326. if ($iAsync && $bBlockVisible) {
  327. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  328. $aParams = array(
  329. $this->getBlockTitle($aBlock),
  330. $sContent,
  331. $aBlock['designbox_id']
  332. );
  333. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  334. }
  335. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  336. $mixedContent = $this->$sFunc($aBlock);
  337. $sTitle = $this->getBlockTitle($aBlock);
  338. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  339. $aParams = array(
  340. isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle,
  341. $mixedContent['content'],
  342. isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id']
  343. );
  344. $mixedMenu = false;
  345. if(isset($mixedContent['menu']))
  346. $mixedMenu = $mixedContent['menu'];
  347. else if(!empty($aBlock['submenu']))
  348. $mixedMenu = $aBlock['submenu'];
  349. $aParams[] = $mixedMenu;
  350. if(isset($mixedContent['buttons']))
  351. $aParams[] = $mixedContent['buttons'];
  352. else if($mixedMenu)
  353. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  354. }
  355. else if(is_string($mixedContent) && !empty($mixedContent)) {
  356. $aParams = array(
  357. $sTitle,
  358. $mixedContent,
  359. $aBlock['designbox_id']
  360. );
  361. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  362. $aParams[] = $mixedMenu;
  363. if($mixedMenu)
  364. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  365. }
  366. if(!empty($aParams))
  367. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  368. }
  369. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  370. return $sContentWithBox;
  371. }
  372. /**
  373. * Add necessary js and css files.
  374. */
  375. protected function _addJsCss()
  376. {
  377. $this->_oTemplate->addJs('BxDolPage.js');
  378. $this->_oTemplate->addCss('page_sticky.css');
  379. $this->_oTemplate->addCss('page_layouts.css');
  380. }
  381. /**
  382. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  383. */
  384. protected function _addSysTemplateVars ()
  385. {
  386. $oTemplate = BxDolTemplate::getInstance();
  387. $sPageTitle = $this->_getPageTitle();
  388. if ($sPageTitle)
  389. $oTemplate->setPageHeader ($sPageTitle);
  390. $sMetaDesc = $this->_getPageMetaDesc();
  391. if ($sMetaDesc)
  392. $oTemplate->setPageDescription ($sMetaDesc);
  393. $sMetaRobots = $this->_getPageMetaRobots();
  394. if ($sMetaRobots)
  395. $oTemplate->setPageMetaRobots ($sMetaRobots);
  396. $sMetaImage = $this->_getPageMetaImage();
  397. if ($sMetaImage)
  398. $oTemplate->addPageMetaImage($sMetaImage);
  399. $sMetaKeywords = $this->_getPageMetaKeywords();
  400. if ($sMetaKeywords)
  401. $oTemplate->addPageKeywords ($sMetaKeywords);
  402. }
  403. /**
  404. * Select menu from page properties.
  405. */
  406. protected function _selectMenu ()
  407. {
  408. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  409. }
  410. /**
  411. * Set page submenu if it's specified
  412. */
  413. protected function _setSubmenu ($aParams)
  414. {
  415. if(empty($this->_aObject['submenu']))
  416. return;
  417. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  418. if(!$oMenuSubmenu)
  419. return;
  420. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  421. }
  422. /**
  423. * Get content for 'raw' block type.
  424. * @return string
  425. */
  426. protected function _getBlockRaw ($aBlock)
  427. {
  428. $s = '<div class="bx-page-raw-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  429. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  430. $s = bx_process_macros($s);
  431. return $s;
  432. }
  433. /**
  434. * Get content for 'custom' block type.
  435. * @return string
  436. */
  437. protected function _getBlockCustom ($aBlock)
  438. {
  439. $s = '<div class="bx-page-custom-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 'html' block type.
  446. * @return string
  447. */
  448. protected function _getBlockHtml ($aBlock)
  449. {
  450. $s = '<div class="bx-page-html-container">' . $aBlock['content'] . '</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 'wiki' block type.
  457. * @return string
  458. */
  459. protected function _getBlockWiki ($aBlock)
  460. {
  461. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  462. if (!$oWiki) {
  463. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  464. }
  465. else {
  466. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  467. }
  468. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container">' . $sContent . '</div>';
  469. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  470. $s = bx_process_macros($s);
  471. return $s;
  472. }
  473. /**
  474. * Get content for 'lang' block type.
  475. * @return string
  476. */
  477. protected function _getBlockLang ($aBlock)
  478. {
  479. $s = '<div class="bx-page-lang-container">' . _t(trim($aBlock['content'])) . '</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 'image' block type.
  486. * @return string
  487. */
  488. protected function _getBlockImage ($aBlock)
  489. {
  490. if (empty($aBlock['content']))
  491. return false;
  492. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  493. $iFileId = (int)$iFileId;
  494. if (!$iFileId)
  495. return false;
  496. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  497. if (!$oStorage)
  498. return false;
  499. $sUrl = $oStorage->getFileUrlById($iFileId);
  500. if (!$sUrl)
  501. return false;
  502. $sStyleAdd = '';
  503. if ('center' == $sAlign || 'left' == $sAlign || 'right' == $sAlign)
  504. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  505. return '<div class="bx-page-image-container" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  506. }
  507. /**
  508. * Get content for 'rss' block type.
  509. * @return string
  510. */
  511. protected function _getBlockRss ($aBlock)
  512. {
  513. if (empty($aBlock['content']))
  514. return false;
  515. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  516. $iNum = (int)$iNum;
  517. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  518. }
  519. /**
  520. * Get content for 'menu' block type.
  521. * @return string
  522. */
  523. protected function _getBlockMenu ($aBlock)
  524. {
  525. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  526. return $oMenu ? $oMenu->getCode () : '';
  527. }
  528. /**
  529. * Get content for 'service' block type.
  530. * @return string
  531. */
  532. protected function _getBlockService ($aBlock)
  533. {
  534. return BxDolService::callSerialized($aBlock['content'], $this->_aMarkers);
  535. }
  536. /**
  537. * Get page title.
  538. * @return string
  539. */
  540. protected function _getPageTitle()
  541. {
  542. return $this->_replaceMarkers(_t($this->_aObject['title']));
  543. }
  544. /**
  545. * Get page meta description.
  546. * @return string
  547. */
  548. protected function _getPageMetaDesc()
  549. {
  550. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  551. }
  552. /**
  553. * Get page meta image.
  554. * @return string
  555. */
  556. protected function _getPageMetaImage()
  557. {
  558. return '';
  559. }
  560. /**
  561. * Get page meta keywords.
  562. * @return string
  563. */
  564. protected function _getPageMetaKeywords()
  565. {
  566. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  567. }
  568. /**
  569. * Get page meta robots.
  570. * @return string
  571. */
  572. protected function _getPageMetaRobots()
  573. {
  574. return _t($this->_aObject['meta_robots']);
  575. }
  576. /**
  577. * Get access denied message HTML.
  578. * @return string
  579. */
  580. protected function _getPageAccessDeniedMsg ()
  581. {
  582. return MsgBox(_t('_Access denied'));
  583. }
  584. /**
  585. * Get page cache object.
  586. * @return cache object instance
  587. */
  588. protected function _getPageCacheObject ()
  589. {
  590. if ($this->_oPageCacheObject != null) {
  591. return $this->_oPageCacheObject;
  592. } else {
  593. $sEngine = getParam('sys_page_cache_engine');
  594. $this->_oPageCacheObject = bx_instance ('BxDolCache' . $sEngine);
  595. if (!$this->_oPageCacheObject->isAvailable())
  596. $this->_oPageCacheObject = bx_instance ('BxDolCacheFile');
  597. return $this->_oPageCacheObject;
  598. }
  599. }
  600. /**
  601. * Get page cache key.
  602. * @param $isPrefixOnly return key prefix only.
  603. * @return string
  604. */
  605. protected function _getPageCacheKey ($isPrefixOnly = false)
  606. {
  607. $s = 'page_' . $this->_aObject['object'] . '_';
  608. if ($isPrefixOnly)
  609. return $s;
  610. $s .= $this->_getPageCacheParams ();
  611. $s .= bx_site_hash() . '.php';
  612. return $s;
  613. }
  614. /**
  615. * Additional cache key. In the case of dynamic page.
  616. * For example - profile page, where each profile has own page.
  617. * @return string
  618. */
  619. protected function _getPageCacheParams ()
  620. {
  621. return '';
  622. }
  623. /**
  624. * Clean page cache.
  625. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  626. * @return string
  627. */
  628. protected function cleanCache ($isDelAllWithPagePrefix = false)
  629. {
  630. $oCache = $this->_getPageCacheObject ();
  631. $sKey = $this->_getPageCacheKey($isDelAllWithPagePrefix);
  632. if ($isDelAllWithPagePrefix)
  633. return $oCache->removeAllByPrefix($sKey);
  634. else
  635. return $oCache->delData($sKey);
  636. }
  637. }
  638. /** @} */