BxBasePage.php 24 KB

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