BxBasePage.php 31 KB

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