BxBasePage.php 25 KB

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