BxBasePage.php 29 KB

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