BxBasePage.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902
  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. $sTitle = $this->getBlockTitle($aBlock);
  413. $sHelp = $this->getBlockHelp($aBlock);
  414. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  415. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  416. if ($iAsync && $bBlockVisible) {
  417. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  418. $aParams = array(
  419. $sTitle . $sHelp,
  420. $sContent,
  421. $aBlock['designbox_id']
  422. );
  423. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  424. }
  425. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  426. $mixedContent = $this->$sFunc($aBlock);
  427. $this->_oQuery->setReadOnlyMode(true);
  428. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  429. $aParams = array(
  430. (isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle) . $sHelp,
  431. $mixedContent['content'],
  432. isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id']
  433. );
  434. $mixedMenu = false;
  435. if(isset($mixedContent['menu']))
  436. $mixedMenu = $mixedContent['menu'];
  437. else if(!empty($aBlock['submenu']))
  438. $mixedMenu = $aBlock['submenu'];
  439. $aParams[] = $mixedMenu;
  440. if(isset($mixedContent['buttons']))
  441. $aParams[] = $mixedContent['buttons'];
  442. else if($mixedMenu)
  443. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  444. }
  445. else if(is_string($mixedContent) && !empty($mixedContent)) {
  446. $aParams = array(
  447. $sTitle . $sHelp,
  448. $mixedContent,
  449. $aBlock['designbox_id']
  450. );
  451. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  452. $aParams[] = $mixedMenu;
  453. if($mixedMenu)
  454. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  455. }
  456. if(!empty($aParams))
  457. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  458. }
  459. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  460. return $sContentWithBox;
  461. }
  462. /**
  463. * Add necessary js and css files.
  464. */
  465. protected function _addJsCss()
  466. {
  467. $this->_oTemplate->addJs(array('BxDolPage.js', 'theia-sticky-sidebar/ResizeSensor.min.js', 'theia-sticky-sidebar/theia-sticky-sidebar.min.js'));
  468. $this->_oTemplate->addCss('page_layouts.css');
  469. }
  470. /**
  471. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  472. */
  473. protected function _addSysTemplateVars ()
  474. {
  475. $oTemplate = BxDolTemplate::getInstance();
  476. $sPageTitle = $this->_getPageTitle();
  477. if ($sPageTitle)
  478. $oTemplate->setPageHeader ($sPageTitle);
  479. $sMetaDesc = $this->_getPageMetaDesc();
  480. if ($sMetaDesc)
  481. $oTemplate->setPageDescription ($sMetaDesc);
  482. $sMetaRobots = $this->_getPageMetaRobots();
  483. if ($sMetaRobots)
  484. $oTemplate->setPageMetaRobots ($sMetaRobots);
  485. $sMetaImage = $this->_getPageMetaImage();
  486. if ($sMetaImage)
  487. $oTemplate->addPageMetaImage($sMetaImage);
  488. $sMetaKeywords = $this->_getPageMetaKeywords();
  489. if ($sMetaKeywords)
  490. $oTemplate->addPageKeywords ($sMetaKeywords);
  491. }
  492. /**
  493. * Select menu from page properties.
  494. */
  495. protected function _selectMenu ()
  496. {
  497. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  498. }
  499. /**
  500. * Set page submenu if it's specified
  501. */
  502. protected function _setSubmenu ($aParams)
  503. {
  504. if(empty($this->_aObject['submenu']) || $this->_aObject['submenu'] == 'disabled')
  505. return;
  506. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  507. if(!$oMenuSubmenu)
  508. return;
  509. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  510. }
  511. /**
  512. * Get content for 'raw' block type.
  513. * @return string
  514. */
  515. protected function _getBlockRaw ($aBlock)
  516. {
  517. $s = '<div class="bx-page-raw-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  518. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  519. $s = bx_process_macros($s);
  520. return $s;
  521. }
  522. /**
  523. * Get content for 'custom' block type.
  524. * @return string
  525. */
  526. protected function _getBlockCustom ($aBlock)
  527. {
  528. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  529. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  530. $s = bx_process_macros($s);
  531. return $s;
  532. }
  533. /**
  534. * Get content for 'html' block type.
  535. * @return string
  536. */
  537. protected function _getBlockHtml ($aBlock)
  538. {
  539. $s = '<div class="bx-page-html-container">' . $aBlock['content'] . '</div>';
  540. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  541. $s = bx_process_macros($s);
  542. return $s;
  543. }
  544. /**
  545. * Get content for 'wiki' block type.
  546. * @return string
  547. */
  548. protected function _getBlockWiki ($aBlock)
  549. {
  550. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  551. if (!$oWiki) {
  552. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  553. }
  554. else {
  555. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  556. }
  557. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container">' . $sContent . '</div>';
  558. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  559. $s = bx_process_macros($s);
  560. return $s;
  561. }
  562. /**
  563. * Get content for 'lang' block type.
  564. * @return string
  565. */
  566. protected function _getBlockLang ($aBlock)
  567. {
  568. $s = '<div class="bx-page-lang-container">' . _t(trim($aBlock['content'])) . '</div>';
  569. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  570. $s = bx_process_macros($s);
  571. return $s;
  572. }
  573. /**
  574. * Get content for 'image' block type.
  575. * @return string
  576. */
  577. protected function _getBlockImage ($aBlock)
  578. {
  579. if (empty($aBlock['content']))
  580. return false;
  581. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  582. $iFileId = (int)$iFileId;
  583. if (!$iFileId)
  584. return false;
  585. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  586. if (!$oStorage)
  587. return false;
  588. $sUrl = $oStorage->getFileUrlById($iFileId);
  589. if (!$sUrl)
  590. return false;
  591. $sStyleAdd = '';
  592. if ('center' == $sAlign || 'left' == $sAlign || 'right' == $sAlign)
  593. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  594. return '<div class="bx-page-image-container" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  595. }
  596. /**
  597. * Get content for 'rss' block type.
  598. * @return string
  599. */
  600. protected function _getBlockRss ($aBlock)
  601. {
  602. if (empty($aBlock['content']))
  603. return false;
  604. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  605. $iNum = (int)$iNum;
  606. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  607. }
  608. /**
  609. * Get content for 'menu' block type.
  610. * @return string
  611. */
  612. protected function _getBlockMenu ($aBlock)
  613. {
  614. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  615. return $oMenu ? $oMenu->getCode () : '';
  616. }
  617. /**
  618. * Get content for 'service' block type.
  619. * @return string
  620. */
  621. protected function _getBlockService ($aBlock)
  622. {
  623. return BxDolService::callSerialized($aBlock['content'], $this->_aMarkers);
  624. }
  625. /**
  626. * Get page title.
  627. * @return string
  628. */
  629. protected function _getPageTitle()
  630. {
  631. return $this->_replaceMarkers(_t($this->_aObject['title']));
  632. }
  633. /**
  634. * Get page meta description.
  635. * @return string
  636. */
  637. protected function _getPageMetaDesc()
  638. {
  639. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  640. }
  641. /**
  642. * Get page meta image.
  643. * @return string
  644. */
  645. protected function _getPageMetaImage()
  646. {
  647. return '';
  648. }
  649. /**
  650. * Get page meta keywords.
  651. * @return string
  652. */
  653. protected function _getPageMetaKeywords()
  654. {
  655. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  656. }
  657. /**
  658. * Get page meta robots.
  659. * @return string
  660. */
  661. protected function _getPageMetaRobots()
  662. {
  663. return _t($this->_aObject['meta_robots']);
  664. }
  665. /**
  666. * Get access denied message HTML.
  667. * @return string
  668. */
  669. protected function _getPageAccessDeniedMsg ()
  670. {
  671. return MsgBox(_t('_Access denied'));
  672. }
  673. /**
  674. * Get page cache object.
  675. * @return cache object instance
  676. */
  677. protected function _getPageCacheObject ()
  678. {
  679. return $this->_getCacheObject ();
  680. }
  681. /**
  682. * Get block cache object.
  683. * @return cache object instance
  684. */
  685. protected function _getBlockCacheObject ()
  686. {
  687. return $this->_getCacheObject ('Block', 'pb');
  688. }
  689. protected function _getCacheObject ($sSuffixObj = 'Page', $sSuffixParam = 'page')
  690. {
  691. $sObj = '_o' . $sSuffixObj . 'CacheObject';
  692. $sParam = 'sys_' . $sSuffixParam . '_cache_engine';
  693. if ($this->{$sObj} != null) {
  694. return $this->{$sObj};
  695. } else {
  696. $sEngine = getParam($sParam);
  697. $this->{$sObj} = bx_instance ('BxDolCache' . $sEngine);
  698. if (!$this->{$sObj}->isAvailable())
  699. $this->{$sObj} = bx_instance ('BxDolCacheFile');
  700. return $this->{$sObj};
  701. }
  702. }
  703. /**
  704. * Get page cache key.
  705. * @param $isPrefixOnly return key prefix only.
  706. * @return string
  707. */
  708. protected function _getPageCacheKey ($isPrefixOnly = false)
  709. {
  710. $s = 'page_' . $this->_aObject['object'] . '_';
  711. if ($isPrefixOnly)
  712. return $s;
  713. $s .= $this->_getPageCacheParams ();
  714. $s .= bx_site_hash() . '.php';
  715. return $s;
  716. }
  717. /**
  718. * Get block cache key.
  719. * @param $isPrefixOnly return key prefix only.
  720. * @return string
  721. */
  722. protected function _getBlockCacheKey ($isPrefixOnly = false, $aBlock = array())
  723. {
  724. $s = $this->_getPageCacheKey(true) . 'block_';
  725. if ($isPrefixOnly)
  726. return $s;
  727. $s .= ($aBlock ? $aBlock['id'] : 0) . '_' . $this->_getPageCacheParams ();
  728. $s .= bx_site_hash() . '.php';
  729. return $s;
  730. }
  731. /**
  732. * Additional cache key. In the case of dynamic page.
  733. * For example - profile page, where each profile has own page.
  734. * @return string
  735. */
  736. protected function _getPageCacheParams ()
  737. {
  738. return '';
  739. }
  740. /**
  741. * Clean page cache.
  742. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  743. * @return string
  744. */
  745. protected function cleanCache ($isDelAllWithPagePrefix = false)
  746. {
  747. $a = ['Page', 'Block'];
  748. $bRet = false;
  749. foreach ($a as $s) {
  750. $oCache = $this->{'_get' . $s . 'CacheObject'} ();
  751. $sKey = $this->{'_get'. $s . 'CacheKey'} ($isDelAllWithPagePrefix);
  752. if ($isDelAllWithPagePrefix)
  753. $bRet = $bRet && $oCache->removeAllByPrefix($sKey);
  754. else
  755. $bRet = $bRet && $oCache->delData($sKey);
  756. }
  757. return $bRet;
  758. }
  759. }
  760. /** @} */