BxBasePage.php 32 KB

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