1
0

BxBasePage.php 24 KB

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