BxBasePage.php 31 KB

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