BxBasePage.php 31 KB

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