BxBasePage.php 30 KB

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