BxBasePage.php 21 KB

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