BxBasePage.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  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 .= $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
  305. 'class_add' => $sHiddenOn,
  306. 'bx_if:show_html_id' => array(
  307. 'condition' => true,
  308. 'content' => array(
  309. 'html_id' => 'bx-page-block-' . $aBlock['id']
  310. ),
  311. ),
  312. 'content' => $sContentWithBox
  313. ));
  314. }
  315. $aVars[$sKey] = $sCell;
  316. }
  317. return $aVars;
  318. }
  319. /**
  320. * Process block values, especially if someting need to be overrided
  321. */
  322. protected function processPageBlock(&$aBlock, $bApi = false)
  323. {
  324. }
  325. /**
  326. * Get page code only.
  327. * @return string
  328. */
  329. protected function _getPageCode ()
  330. {
  331. $aVars = $this->_getPageCodeVars ();
  332. return $this->_oTemplate->parseHtmlByName($this->_aObject['template'], $aVars);
  333. }
  334. /**
  335. * Get one block code only.
  336. * @return string
  337. */
  338. protected function _getBlockOnlyCode ($iBlockId)
  339. {
  340. if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
  341. return '';
  342. return $this->_getBlockCode($aBlock, 0);
  343. }
  344. /**
  345. * Get block code.
  346. * @return string
  347. */
  348. protected function _getBlockCode($aBlock, $iAsync = 0)
  349. {
  350. $sContentWithBox = '';
  351. $oFunctions = $this->_oTemplate->getTemplateFunctions();
  352. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPageBlock(_t($aBlock['title']), $aBlock['id']);
  353. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  354. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  355. if ($iAsync && $bBlockVisible) {
  356. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  357. $aParams = array(
  358. $this->getBlockTitle($aBlock),
  359. $sContent,
  360. $aBlock['designbox_id']
  361. );
  362. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  363. }
  364. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  365. $mixedContent = $this->$sFunc($aBlock);
  366. $sTitle = $this->getBlockTitle($aBlock);
  367. $this->_oQuery->setReadOnlyMode(true);
  368. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  369. $aParams = array(
  370. isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle,
  371. $mixedContent['content'],
  372. isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id']
  373. );
  374. $mixedMenu = false;
  375. if(isset($mixedContent['menu']))
  376. $mixedMenu = $mixedContent['menu'];
  377. else if(!empty($aBlock['submenu']))
  378. $mixedMenu = $aBlock['submenu'];
  379. $aParams[] = $mixedMenu;
  380. if(isset($mixedContent['buttons']))
  381. $aParams[] = $mixedContent['buttons'];
  382. else if($mixedMenu)
  383. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  384. }
  385. else if(is_string($mixedContent) && !empty($mixedContent)) {
  386. $aParams = array(
  387. $sTitle,
  388. $mixedContent,
  389. $aBlock['designbox_id']
  390. );
  391. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  392. $aParams[] = $mixedMenu;
  393. if($mixedMenu)
  394. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  395. }
  396. if(!empty($aParams))
  397. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  398. }
  399. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  400. return $sContentWithBox;
  401. }
  402. /**
  403. * Add necessary js and css files.
  404. */
  405. protected function _addJsCss()
  406. {
  407. $this->_oTemplate->addJs(array('BxDolPage.js', 'theia-sticky-sidebar/ResizeSensor.min.js', 'theia-sticky-sidebar/theia-sticky-sidebar.min.js'));
  408. $this->_oTemplate->addCss('page_layouts.css');
  409. }
  410. /**
  411. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  412. */
  413. protected function _addSysTemplateVars ()
  414. {
  415. $oTemplate = BxDolTemplate::getInstance();
  416. $sPageTitle = $this->_getPageTitle();
  417. if ($sPageTitle)
  418. $oTemplate->setPageHeader ($sPageTitle);
  419. $sMetaDesc = $this->_getPageMetaDesc();
  420. if ($sMetaDesc)
  421. $oTemplate->setPageDescription ($sMetaDesc);
  422. $sMetaRobots = $this->_getPageMetaRobots();
  423. if ($sMetaRobots)
  424. $oTemplate->setPageMetaRobots ($sMetaRobots);
  425. $sMetaImage = $this->_getPageMetaImage();
  426. if ($sMetaImage)
  427. $oTemplate->addPageMetaImage($sMetaImage);
  428. $sMetaKeywords = $this->_getPageMetaKeywords();
  429. if ($sMetaKeywords)
  430. $oTemplate->addPageKeywords ($sMetaKeywords);
  431. }
  432. /**
  433. * Select menu from page properties.
  434. */
  435. protected function _selectMenu ()
  436. {
  437. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  438. }
  439. /**
  440. * Set page submenu if it's specified
  441. */
  442. protected function _setSubmenu ($aParams)
  443. {
  444. if(empty($this->_aObject['submenu']))
  445. return;
  446. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  447. if(!$oMenuSubmenu)
  448. return;
  449. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  450. }
  451. /**
  452. * Get content for 'raw' block type.
  453. * @return string
  454. */
  455. protected function _getBlockRaw ($aBlock)
  456. {
  457. $s = '<div class="bx-page-raw-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  458. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  459. $s = bx_process_macros($s);
  460. return $s;
  461. }
  462. /**
  463. * Get content for 'custom' block type.
  464. * @return string
  465. */
  466. protected function _getBlockCustom ($aBlock)
  467. {
  468. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  469. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  470. $s = bx_process_macros($s);
  471. return $s;
  472. }
  473. /**
  474. * Get content for 'html' block type.
  475. * @return string
  476. */
  477. protected function _getBlockHtml ($aBlock)
  478. {
  479. $s = '<div class="bx-page-html-container">' . $aBlock['content'] . '</div>';
  480. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  481. $s = bx_process_macros($s);
  482. return $s;
  483. }
  484. /**
  485. * Get content for 'wiki' block type.
  486. * @return string
  487. */
  488. protected function _getBlockWiki ($aBlock)
  489. {
  490. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  491. if (!$oWiki) {
  492. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  493. }
  494. else {
  495. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  496. }
  497. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container">' . $sContent . '</div>';
  498. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  499. $s = bx_process_macros($s);
  500. return $s;
  501. }
  502. /**
  503. * Get content for 'lang' block type.
  504. * @return string
  505. */
  506. protected function _getBlockLang ($aBlock)
  507. {
  508. $s = '<div class="bx-page-lang-container">' . _t(trim($aBlock['content'])) . '</div>';
  509. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  510. $s = bx_process_macros($s);
  511. return $s;
  512. }
  513. /**
  514. * Get content for 'image' block type.
  515. * @return string
  516. */
  517. protected function _getBlockImage ($aBlock)
  518. {
  519. if (empty($aBlock['content']))
  520. return false;
  521. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  522. $iFileId = (int)$iFileId;
  523. if (!$iFileId)
  524. return false;
  525. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  526. if (!$oStorage)
  527. return false;
  528. $sUrl = $oStorage->getFileUrlById($iFileId);
  529. if (!$sUrl)
  530. return false;
  531. $sStyleAdd = '';
  532. if ('center' == $sAlign || 'left' == $sAlign || 'right' == $sAlign)
  533. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  534. return '<div class="bx-page-image-container" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  535. }
  536. /**
  537. * Get content for 'rss' block type.
  538. * @return string
  539. */
  540. protected function _getBlockRss ($aBlock)
  541. {
  542. if (empty($aBlock['content']))
  543. return false;
  544. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  545. $iNum = (int)$iNum;
  546. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  547. }
  548. /**
  549. * Get content for 'menu' block type.
  550. * @return string
  551. */
  552. protected function _getBlockMenu ($aBlock)
  553. {
  554. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  555. return $oMenu ? $oMenu->getCode () : '';
  556. }
  557. /**
  558. * Get content for 'service' block type.
  559. * @return string
  560. */
  561. protected function _getBlockService ($aBlock)
  562. {
  563. return BxDolService::callSerialized($aBlock['content'], $this->_aMarkers);
  564. }
  565. /**
  566. * Get page title.
  567. * @return string
  568. */
  569. protected function _getPageTitle()
  570. {
  571. return $this->_replaceMarkers(_t($this->_aObject['title']));
  572. }
  573. /**
  574. * Get page meta description.
  575. * @return string
  576. */
  577. protected function _getPageMetaDesc()
  578. {
  579. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  580. }
  581. /**
  582. * Get page meta image.
  583. * @return string
  584. */
  585. protected function _getPageMetaImage()
  586. {
  587. return '';
  588. }
  589. /**
  590. * Get page meta keywords.
  591. * @return string
  592. */
  593. protected function _getPageMetaKeywords()
  594. {
  595. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  596. }
  597. /**
  598. * Get page meta robots.
  599. * @return string
  600. */
  601. protected function _getPageMetaRobots()
  602. {
  603. return _t($this->_aObject['meta_robots']);
  604. }
  605. /**
  606. * Get access denied message HTML.
  607. * @return string
  608. */
  609. protected function _getPageAccessDeniedMsg ()
  610. {
  611. return MsgBox(_t('_Access denied'));
  612. }
  613. /**
  614. * Get page cache object.
  615. * @return cache object instance
  616. */
  617. protected function _getPageCacheObject ()
  618. {
  619. if ($this->_oPageCacheObject != null) {
  620. return $this->_oPageCacheObject;
  621. } else {
  622. $sEngine = getParam('sys_page_cache_engine');
  623. $this->_oPageCacheObject = bx_instance ('BxDolCache' . $sEngine);
  624. if (!$this->_oPageCacheObject->isAvailable())
  625. $this->_oPageCacheObject = bx_instance ('BxDolCacheFile');
  626. return $this->_oPageCacheObject;
  627. }
  628. }
  629. /**
  630. * Get page cache key.
  631. * @param $isPrefixOnly return key prefix only.
  632. * @return string
  633. */
  634. protected function _getPageCacheKey ($isPrefixOnly = false)
  635. {
  636. $s = 'page_' . $this->_aObject['object'] . '_';
  637. if ($isPrefixOnly)
  638. return $s;
  639. $s .= $this->_getPageCacheParams ();
  640. $s .= bx_site_hash() . '.php';
  641. return $s;
  642. }
  643. /**
  644. * Additional cache key. In the case of dynamic page.
  645. * For example - profile page, where each profile has own page.
  646. * @return string
  647. */
  648. protected function _getPageCacheParams ()
  649. {
  650. return '';
  651. }
  652. /**
  653. * Clean page cache.
  654. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  655. * @return string
  656. */
  657. protected function cleanCache ($isDelAllWithPagePrefix = false)
  658. {
  659. $oCache = $this->_getPageCacheObject ();
  660. $sKey = $this->_getPageCacheKey($isDelAllWithPagePrefix);
  661. if ($isDelAllWithPagePrefix)
  662. return $oCache->removeAllByPrefix($sKey);
  663. else
  664. return $oCache->delData($sKey);
  665. }
  666. }
  667. /** @} */