BxBasePage.php 30 KB

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