BxBasePage.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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)) {
  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))
  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. $sHiddenOn = '';
  384. if(!empty($aBlock['hidden_on']))
  385. foreach($aHiddenOn as $iHiddenOn => $sClass)
  386. if((int)$aBlock['hidden_on'] & $iHiddenOn)
  387. $sHiddenOn .= ' ' . $sClass;
  388. if ($sContentWithBox)
  389. $sCell .= $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
  390. 'class_add' => $sHiddenOn,
  391. 'bx_if:show_html_id' => array(
  392. 'condition' => true,
  393. 'content' => array(
  394. 'html_id' => 'bx-page-block-' . $aBlock['id']
  395. ),
  396. ),
  397. 'content' => $sContentWithBox
  398. ));
  399. }
  400. $aVars[$sKey] = $sCell;
  401. }
  402. return $aVars;
  403. }
  404. /**
  405. * Process block values, especially if someting need to be overrided
  406. */
  407. protected function processPageBlock(&$aBlock, $bApi = false)
  408. {
  409. }
  410. /**
  411. * Get page code only.
  412. * @return string
  413. */
  414. protected function _getPageCode ()
  415. {
  416. $aVars = $this->_getPageCodeVars ();
  417. return $this->_oTemplate->parseHtmlByName($this->_aObject['template'], $aVars);
  418. }
  419. /**
  420. * Get one block code only.
  421. * @return string
  422. */
  423. protected function _getBlockOnlyCode ($iBlockId)
  424. {
  425. if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
  426. return '';
  427. return $this->_getBlockCodeWithCache($aBlock, 0);
  428. }
  429. protected function _getBlockCodeWithCache($aBlock, $iAsync = 0)
  430. {
  431. if (!getParam('sys_pb_cache_enable') || !$aBlock['cache_lifetime'] || $iAsync || (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST')) {
  432. $sBlockCode = $this->_getBlockCode($aBlock, $iAsync);
  433. }
  434. else {
  435. $oCache = $this->_getBlockCacheObject();
  436. $sKey = $this->_getBlockCacheKey(false, $aBlock);
  437. $sKeyCssJs = 'cssjs_' . $sKey;
  438. $mixedRet = $oCache->getData($sKey, $aBlock['cache_lifetime']);
  439. $aRetCssJs = $oCache->getData($sKeyCssJs, $aBlock['cache_lifetime']);
  440. if ($mixedRet !== null && $aRetCssJs !== null) {
  441. BxDolTemplate::getInstance()->collectingStart();
  442. BxDolTemplate::getInstance()->collectingInject($aRetCssJs['css'], $aRetCssJs['js']);
  443. $sBlockCode = BxDolTemplate::getInstance()->collectingEndGetCode();
  444. $sBlockCode .= $mixedRet;
  445. } else {
  446. BxDolTemplate::getInstance()->collectingStart();
  447. $sBlockCode = $this->_getBlockCode($aBlock, $iAsync);
  448. $aBlockCssJs = BxDolTemplate::getInstance()->collectingEndGetCode(array(), array(), 'array');
  449. $oCache->setData($sKey, $sBlockCode, $aBlock['cache_lifetime']);
  450. $oCache->setData($sKeyCssJs, $aBlockCssJs, $aBlock['cache_lifetime']);
  451. }
  452. }
  453. return $sBlockCode;
  454. }
  455. /**
  456. * Get block code.
  457. * @return string
  458. */
  459. protected function _getBlockCode($aBlock, $iAsync = 0)
  460. {
  461. $sContentWithBox = '';
  462. $oFunctions = $this->_oTemplate->getTemplateFunctions();
  463. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPageBlock(_t($aBlock['title']), $aBlock['id']);
  464. $aDbNoTitle = [BX_DB_CONTENT_ONLY, BX_DB_PADDING_CONTENT_ONLY, BX_DB_NO_CAPTION, BX_DB_PADDING_NO_CAPTION];
  465. $sTitle = $this->getBlockTitle($aBlock);
  466. $sHelp = $this->getBlockHelp($aBlock);
  467. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  468. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  469. if ($iAsync && $bBlockVisible) {
  470. $iDesignboxId = $aBlock['designbox_id'];
  471. $sHelpTitle = $sHelpContent = '';
  472. if(!in_array($iDesignboxId, $aDbNoTitle))
  473. $sHelpTitle = $sHelp;
  474. else
  475. $sHelpContent = $sHelp;
  476. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  477. $aParams = array(
  478. $sTitle . $sHelpTitle,
  479. $sContent . $sHelpContent,
  480. $iDesignboxId
  481. );
  482. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  483. }
  484. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  485. $mixedContent = $this->$sFunc($aBlock);
  486. $this->_oQuery->setReadOnlyMode(true);
  487. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  488. $iDesignboxId = isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id'];
  489. $sHelpTitle = $sHelpContent = '';
  490. if(!in_array($iDesignboxId, $aDbNoTitle))
  491. $sHelpTitle = $sHelp;
  492. else
  493. $sHelpContent = $sHelp;
  494. $aParams = array(
  495. (isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle) . $sHelpTitle,
  496. $mixedContent['content'] . $sHelpContent,
  497. $iDesignboxId
  498. );
  499. $mixedMenu = false;
  500. if(isset($mixedContent['menu']))
  501. $mixedMenu = $mixedContent['menu'];
  502. else if(!empty($aBlock['submenu']))
  503. $mixedMenu = $aBlock['submenu'];
  504. $aParams[] = $mixedMenu;
  505. if(isset($mixedContent['buttons']))
  506. $aParams[] = $mixedContent['buttons'];
  507. else if($mixedMenu)
  508. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  509. }
  510. else if(is_string($mixedContent) && !empty($mixedContent)) {
  511. $iDesignboxId = $aBlock['designbox_id'];
  512. $sHelpTitle = $sHelpContent = '';
  513. if(!in_array($iDesignboxId, $aDbNoTitle))
  514. $sHelpTitle = $sHelp;
  515. else
  516. $sHelpContent = $sHelp;
  517. $aParams = array(
  518. $sTitle . $sHelpTitle,
  519. $mixedContent . $sHelpContent,
  520. $iDesignboxId
  521. );
  522. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  523. $aParams[] = $mixedMenu;
  524. if($mixedMenu)
  525. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  526. }
  527. if(!empty($aParams))
  528. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  529. }
  530. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  531. return $sContentWithBox;
  532. }
  533. /**
  534. * Add necessary js and css files.
  535. */
  536. protected function _addJsCss()
  537. {
  538. $this->_oTemplate->addJs(array('BxDolPage.js', 'theia-sticky-sidebar/ResizeSensor.min.js', 'theia-sticky-sidebar/theia-sticky-sidebar.min.js'));
  539. $this->_oTemplate->addCss('page_layouts.css');
  540. }
  541. /**
  542. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  543. */
  544. protected function _addSysTemplateVars ()
  545. {
  546. $oTemplate = BxDolTemplate::getInstance();
  547. $sPageTitle = $this->_getPageTitle();
  548. if ($sPageTitle)
  549. $oTemplate->setPageHeader ($sPageTitle);
  550. $sMetaDesc = $this->_getPageMetaDesc();
  551. if ($sMetaDesc)
  552. $oTemplate->setPageDescription ($sMetaDesc);
  553. $sMetaRobots = $this->_getPageMetaRobots();
  554. if ($sMetaRobots)
  555. $oTemplate->setPageMetaRobots ($sMetaRobots);
  556. $sMetaImage = $this->_getPageMetaImage();
  557. if ($sMetaImage)
  558. $oTemplate->addPageMetaImage($sMetaImage);
  559. $sMetaKeywords = $this->_getPageMetaKeywords();
  560. if ($sMetaKeywords)
  561. $oTemplate->addPageKeywords ($sMetaKeywords);
  562. }
  563. /**
  564. * Select menu from page properties.
  565. */
  566. protected function _selectMenu ()
  567. {
  568. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  569. }
  570. /**
  571. * Set page submenu if it's specified
  572. */
  573. protected function _setSubmenu ($aParams)
  574. {
  575. if(empty($this->_aObject['submenu']) || $this->_aObject['submenu'] == 'disabled')
  576. return;
  577. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  578. if(!$oMenuSubmenu)
  579. return;
  580. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  581. }
  582. /**
  583. * Get content for 'raw' block type.
  584. * @return string
  585. */
  586. protected function _getBlockRaw ($aBlock)
  587. {
  588. $s = '<div class="bx-page-raw-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  589. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  590. $s = bx_process_macros($s);
  591. return $s;
  592. }
  593. /**
  594. * Get content for 'custom' block type.
  595. * @return string
  596. */
  597. protected function _getBlockCustom ($aBlock)
  598. {
  599. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  600. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  601. $s = bx_process_macros($s);
  602. return $s;
  603. }
  604. /**
  605. * Get content for 'html' block type.
  606. * @return string
  607. */
  608. protected function _getBlockHtml ($aBlock)
  609. {
  610. $s = '<div class="bx-page-html-container">' . $aBlock['content'] . '</div>';
  611. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  612. $s = bx_process_macros($s);
  613. return $s;
  614. }
  615. /**
  616. * Get content for 'wiki' block type.
  617. * @return string
  618. */
  619. protected function _getBlockWiki ($aBlock)
  620. {
  621. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  622. if (!$oWiki) {
  623. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  624. }
  625. else {
  626. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  627. }
  628. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container markdown-body">' . $sContent . '</div>';
  629. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  630. $s = bx_process_macros($s);
  631. return $s;
  632. }
  633. /**
  634. * Get content for 'lang' block type.
  635. * @return string
  636. */
  637. protected function _getBlockLang ($aBlock)
  638. {
  639. $s = '<div class="bx-page-lang-container">' . _t(trim($aBlock['content'])) . '</div>';
  640. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  641. $s = bx_process_macros($s);
  642. return $s;
  643. }
  644. /**
  645. * Get content for 'image' block type.
  646. * @return string
  647. */
  648. protected function _getBlockImage ($aBlock)
  649. {
  650. if (empty($aBlock['content']))
  651. return false;
  652. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  653. $iFileId = (int)$iFileId;
  654. if (!$iFileId)
  655. return false;
  656. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  657. if (!$oStorage)
  658. return false;
  659. $sUrl = $oStorage->getFileUrlById($iFileId);
  660. if (!$sUrl)
  661. return false;
  662. $sStyleAdd = '';
  663. if ('center' == $sAlign || 'left' == $sAlign || 'right' == $sAlign)
  664. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  665. return '<div class="bx-page-image-container" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  666. }
  667. /**
  668. * Get content for 'rss' block type.
  669. * @return string
  670. */
  671. protected function _getBlockRss ($aBlock)
  672. {
  673. if (empty($aBlock['content']))
  674. return false;
  675. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  676. $iNum = (int)$iNum;
  677. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  678. }
  679. /**
  680. * Get content for 'menu' block type.
  681. * @return string
  682. */
  683. protected function _getBlockMenu ($aBlock)
  684. {
  685. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  686. return $oMenu ? $oMenu->getCode () : '';
  687. }
  688. /**
  689. * Get content for 'service' block type.
  690. * @return string
  691. */
  692. protected function _getBlockService ($aBlock)
  693. {
  694. return BxDolService::callSerialized($aBlock['content'], $this->_aMarkers);
  695. }
  696. /**
  697. * Get page title.
  698. * @return string
  699. */
  700. protected function _getPageTitle()
  701. {
  702. return $this->_replaceMarkers(_t($this->_aObject['title']));
  703. }
  704. /**
  705. * Get page meta description.
  706. * @return string
  707. */
  708. protected function _getPageMetaDesc()
  709. {
  710. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  711. }
  712. /**
  713. * Get page meta image.
  714. * @return string
  715. */
  716. protected function _getPageMetaImage()
  717. {
  718. return '';
  719. }
  720. /**
  721. * Get page meta keywords.
  722. * @return string
  723. */
  724. protected function _getPageMetaKeywords()
  725. {
  726. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  727. }
  728. /**
  729. * Get page meta robots.
  730. * @return string
  731. */
  732. protected function _getPageMetaRobots()
  733. {
  734. return _t($this->_aObject['meta_robots']);
  735. }
  736. /**
  737. * Get access denied message HTML.
  738. * @return string
  739. */
  740. protected function _getPageAccessDeniedMsg ()
  741. {
  742. return MsgBox(_t('_Access denied'));
  743. }
  744. /**
  745. * Get page cache object.
  746. * @return cache object instance
  747. */
  748. protected function _getPageCacheObject ()
  749. {
  750. return $this->_getCacheObject ();
  751. }
  752. /**
  753. * Get block cache object.
  754. * @return cache object instance
  755. */
  756. protected function _getBlockCacheObject ()
  757. {
  758. return $this->_getCacheObject ('Block', 'pb');
  759. }
  760. protected function _getCacheObject ($sSuffixObj = 'Page', $sSuffixParam = 'page')
  761. {
  762. $sObj = '_o' . $sSuffixObj . 'CacheObject';
  763. $sParam = 'sys_' . $sSuffixParam . '_cache_engine';
  764. if ($this->{$sObj} != null) {
  765. return $this->{$sObj};
  766. } else {
  767. $sEngine = getParam($sParam);
  768. $this->{$sObj} = bx_instance ('BxDolCache' . $sEngine);
  769. if (!$this->{$sObj}->isAvailable())
  770. $this->{$sObj} = bx_instance ('BxDolCacheFile');
  771. return $this->{$sObj};
  772. }
  773. }
  774. /**
  775. * Get page cache key.
  776. * @param $isPrefixOnly return key prefix only.
  777. * @return string
  778. */
  779. protected function _getPageCacheKey ($isPrefixOnly = false)
  780. {
  781. $s = 'page_' . $this->_aObject['object'] . '_';
  782. if ($isPrefixOnly)
  783. return $s;
  784. $s .= $this->_getPageCacheParams ();
  785. $s .= bx_site_hash() . '.php';
  786. return $s;
  787. }
  788. /**
  789. * Get block cache key.
  790. * @param $isPrefixOnly return key prefix only.
  791. * @return string
  792. */
  793. protected function _getBlockCacheKey ($isPrefixOnly = false, $aBlock = array())
  794. {
  795. $s = $this->_getPageCacheKey(true) . 'block_';
  796. if ($isPrefixOnly)
  797. return $s;
  798. $s .= ($aBlock ? $aBlock['id'] : 0) . '_' . $this->_getPageCacheParams ();
  799. $s .= bx_site_hash() . '.php';
  800. return $s;
  801. }
  802. /**
  803. * Additional cache key. In the case of dynamic page.
  804. * For example - profile page, where each profile has own page.
  805. * @return string
  806. */
  807. protected function _getPageCacheParams ()
  808. {
  809. return md5(serialize($_GET) . bx_lang_name());
  810. }
  811. /**
  812. * Clean page cache.
  813. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  814. * @return string
  815. */
  816. protected function cleanCache ($isDelAllWithPagePrefix = false)
  817. {
  818. $a = ['Page', 'Block'];
  819. $bRet = false;
  820. foreach ($a as $s) {
  821. $oCache = $this->{'_get' . $s . 'CacheObject'} ();
  822. $sKey = $this->{'_get'. $s . 'CacheKey'} ($isDelAllWithPagePrefix);
  823. if ($isDelAllWithPagePrefix)
  824. $bRet = $bRet && $oCache->removeAllByPrefix($sKey);
  825. else
  826. $bRet = $bRet && $oCache->delData($sKey);
  827. }
  828. return $bRet;
  829. }
  830. }
  831. /** @} */