BxBasePage.php 32 KB

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