BxBasePage.php 24 KB

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