BxBasePage.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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 $_sJsClassName = '';
  21. protected $_sJsObjectName = '';
  22. protected $_aHtmlIds = [];
  23. protected $_bStickyColumns = false;
  24. protected $_bSubPage = false;
  25. public function __construct ($aObject, $oTemplate)
  26. {
  27. parent::__construct ($aObject);
  28. if ($oTemplate)
  29. $this->_oTemplate = $oTemplate;
  30. else
  31. $this->_oTemplate = BxDolTemplate::getInstance();
  32. $this->_sStorage = 'sys_images';
  33. $this->_sJsClassName = 'BxDolPage';
  34. $this->_sJsObjectName = 'oBxDolPage';
  35. $this->_bStickyColumns = isset($this->_aObject['sticky_columns']) && $this->_aObject['sticky_columns'] == 1;
  36. $sHtmlId = str_replace(array('_' , ' '), array('-', '-'), $this->_sObject);
  37. $this->_aHtmlIds = array(
  38. 'help_popup' => $sHtmlId . '-help-popup-',
  39. );
  40. $this->addMarkers(array('site_title' => getParam('site_title')));
  41. if (isLogged() && $oProfile = BxDolProfile::getInstance()) {
  42. $this->addMarkers([
  43. 'logged_profile_id' => $oProfile->id(),
  44. 'logged_account_id' => $oProfile->getAccountId(),
  45. 'logged_profile_module' => $oProfile->getModule(),
  46. 'logged_display_name' => $oProfile->getDisplayName(),
  47. 'logged_profile_url' => $oProfile->getUrl(),
  48. ]);
  49. }
  50. if (isset($GLOBALS['bxReplaceableMarkersPages'])) {
  51. $this->addMarkers($GLOBALS['bxReplaceableMarkersPages']);
  52. }
  53. }
  54. public function performActionGetHelp ()
  55. {
  56. $iBlockId = (int)bx_get('block_id');
  57. if(empty($iBlockId))
  58. return;
  59. $aBlock = $this->_oQuery->getPageBlock($iBlockId);
  60. if(empty($aBlock) || !is_array($aBlock) || empty($aBlock['help']))
  61. return;
  62. echo $this->_oTemplate->parseHtmlByName('designbox_help_popup.html', array(
  63. 'content' => _t($aBlock['help'])
  64. ));
  65. }
  66. public function performActionGetShare ()
  67. {
  68. $aEmbedData = BxDolPage::getEmbedData(bx_get('url'));
  69. if(!isset($aEmbedData['url']))
  70. return;
  71. $sMenu = '';
  72. if(getParam('sys_a2a_enable') != 'on') {
  73. if(($oMenu = BxDolMenu::getObjectInstance('sys_social_sharing')) !== false) {
  74. $oMenu->addMarkers([
  75. 'url' => $aEmbedData['url'],
  76. 'img_url_encoded' => '',
  77. 'title_encoded' => ''
  78. ]);
  79. $sMenu = $oMenu->getCode();
  80. }
  81. }
  82. else
  83. $sMenu = getParam('sys_a2a_code');
  84. echo PopupBox('sys_share_popup', _t('_sys_txt_share_popup_header'), $this->_oTemplate->parseHtmlByName('designbox_share_popup.html', [
  85. 'url' => bx_process_output($aEmbedData['url']),
  86. 'menu' => $sMenu,
  87. 'code' => htmlspecialchars($aEmbedData['html']),
  88. ]), true);
  89. }
  90. public function performActionEmbed ()
  91. {
  92. $aCover = $this->getPageCoverImage();
  93. $sTitle = $this->_getPageTitle();
  94. $this->_oTemplate->getEmbed($this->_oTemplate->parseHtmlByName('embed_card.html', [
  95. 'title' => $sTitle,
  96. 'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
  97. 'bx_if:thumb' => [
  98. 'condition' => $this->isPageCover() && count($aCover) > 0,
  99. 'content' => [
  100. 'title' => $sTitle,
  101. 'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
  102. 'background' => BxDolCover::getInstance(BxDolTemplate::getInstance())->getCoverImageUrl($aCover)
  103. ],
  104. ],
  105. 'bx_if:no_thumb' => [
  106. 'condition' => count($aCover) == 0 || !$this->isPageCover(),
  107. 'content' => [
  108. 'title' => $sTitle,
  109. 'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
  110. ]
  111. ]
  112. ]
  113. ));
  114. }
  115. public function performActionCreativeSave()
  116. {
  117. if(!$this->isAllowedCreativeManage())
  118. return echoJson(['code' => 1]);
  119. $iId = 0;
  120. $sContent = '';
  121. if(($iId = bx_get('b')) === false || ($sContent = bx_get('c')) === false)
  122. return echoJson(['code' => 2]);
  123. $iId = bx_process_input($iId, BX_DATA_INT);
  124. $sContent = bx_process_input($sContent, BX_DATA_HTML);
  125. if(!$this->_oQuery->setPageBlockContent($iId, $sContent))
  126. return echoJson(['code' => 3]);
  127. return echoJson(['code' => 0]);
  128. }
  129. public function isAllowedCreativeManage()
  130. {
  131. return isAdmin();
  132. }
  133. /**
  134. * Very similar to BxBasePage::getCode
  135. * but adds css and js files which are needed for the corect page display
  136. */
  137. public function getCodeDynamic ()
  138. {
  139. // TODO: remake to use use collect* template methods
  140. $oTemplate = BxDolTemplate::getInstance();
  141. // get js&css before the page code is generated
  142. $aCssBefore = $oTemplate->getCss();
  143. $aJsBefore = $oTemplate->getJs();
  144. // generate page code
  145. $sContent = $this->getCode();
  146. // get js&css after the page code is generated
  147. $aCssAfter = $oTemplate->getCss();
  148. $aJsAfter = $oTemplate->getJs();
  149. // compare files which were added before and after page code is generated
  150. $f = function ($a1, $a2) {
  151. return strcasecmp($a1['url'], $a2['url']);
  152. };
  153. $aCssNew = array_udiff($aCssAfter, $aCssBefore, $f);
  154. $aJsNew = array_udiff($aJsAfter, $aJsBefore, $f);
  155. // add newly added js&css files in static mode
  156. $sCss = $sJs = '';
  157. foreach ($aCssNew as $a)
  158. $sCss .= $oTemplate->addCss($a['url'], true);
  159. foreach ($aJsNew as $a)
  160. $sJs .= $oTemplate->addJs($a['url'], true);
  161. return $sJs . $sCss . $sContent;
  162. }
  163. public function getIncludes ()
  164. {
  165. $oTemplate = BxDolTemplate::getInstance();
  166. // generate page code
  167. $this->getCode();
  168. // get js&css after the page code is generated
  169. $aCss = $oTemplate->getCss();
  170. $aJs = $oTemplate->getJs();
  171. // add js&css files in static mode
  172. $sResult = '';
  173. foreach ($aCss as $a)
  174. $sResult .= $oTemplate->addCss($a['url'], true);
  175. foreach ($aJs as $a)
  176. $sResult .= $oTemplate->addJs($a['url'], true);
  177. // add js translations
  178. $sResult .= $oTemplate->getJsTranslation(true);
  179. return $sResult;
  180. }
  181. /**
  182. * Get page code with automatic caching, adding necessary css/js files and system template vars.
  183. * @return string.
  184. */
  185. public function getCode ()
  186. {
  187. if (bx_get('dynamic') && ($iBlockId = (int)bx_get('pageBlock'))) {
  188. if (self::isLockedFromUnauthenticated($this->_aObject['uri']) || !$this->_isVisiblePage($this->_aObject)) {
  189. header('HTTP/1.0 403 Forbidden');
  190. exit;
  191. }
  192. /**
  193. * @hooks
  194. * @hookdef hook-system-page_output_block 'system', 'page_output_block' - hook with page block data to be output
  195. * - $unit_name - equals `system`
  196. * - $action - equals `page_output_block`
  197. * - $object_id - not used
  198. * - $sender_id - not used
  199. * - $extra_params - array of additional params with the following array keys:
  200. * - `page_name` - [string] page object name
  201. * - `page_object` - [object] an instance of page class, @see BxDolPage
  202. * - `page_query` - [object] an instance of page related query class
  203. * - `block_id` - [int] block id
  204. * @hook @ref hook-system-page_output_block
  205. */
  206. bx_alert('system', 'page_output_block', 0, false, [
  207. 'page_name' => $this->_sObject,
  208. 'page_object' => $this,
  209. 'page_query' => $this->_oQuery,
  210. 'block_id' => (int)$iBlockId,
  211. ]);
  212. header( 'Content-type:text/html;charset=utf-8' );
  213. BxDolTemplate::getInstance()->collectingStart();
  214. $s = $this->_getBlockOnlyCode($iBlockId);
  215. $sCss = bx_get('includedCss');
  216. $sJs = bx_get('includedJs');
  217. echo BxDolTemplate::getInstance()->collectingEndGetCode($sCss ? @json_decode($sCss) : [], $sJs ? @json_decode($sJs) : []);
  218. echo $s;
  219. exit;
  220. }
  221. if (($mixedAvailable = $this->_isAvailablePage($this->_aObject)) !== true)
  222. return $this->_getPageNotFoundMsg($mixedAvailable);
  223. if (($mixedVisible = $this->_isVisiblePage($this->_aObject)) !== true)
  224. return $this->_getPageAccessDeniedMsg($mixedVisible);
  225. $this->_addJsCss();
  226. if (!$this->_bSubPage) {
  227. $this->_addSysTemplateVars();
  228. $this->_selectMenu();
  229. $this->_setSubmenu(array());
  230. }
  231. if (bx_is_dbg() || !getParam('sys_page_cache_enable') || !$this->_aObject['cache_lifetime'] || (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST')) {
  232. $sPageCode = $this->_getPageCode();
  233. }
  234. else {
  235. $oCache = $this->_getPageCacheObject();
  236. $sKey = $this->_getPageCacheKey();
  237. $sKeyCssJs = 'cssjs_' . $sKey;
  238. $mixedRet = $oCache->getData($sKey, $this->_aObject['cache_lifetime']);
  239. $aRetCssJs = $oCache->getData($sKeyCssJs, $this->_aObject['cache_lifetime']);
  240. if ($mixedRet !== null && $aRetCssJs !== null) {
  241. BxDolTemplate::getInstance()->collectingStart();
  242. BxDolTemplate::getInstance()->collectingInject($aRetCssJs['css'], $aRetCssJs['js']);
  243. $sPageCode = BxDolTemplate::getInstance()->collectingEndGetCode();
  244. $sPageCode .= $mixedRet;
  245. } else {
  246. BxDolTemplate::getInstance()->collectingStart();
  247. $sPageCode = $this->_getPageCode();
  248. $aPageCssJs = BxDolTemplate::getInstance()->collectingEndGetCode(array(), array(), 'array');
  249. $oCache->setData($sKey, $sPageCode, $this->_aObject['cache_lifetime']);
  250. $oCache->setData($sKeyCssJs, $aPageCssJs, $this->_aObject['cache_lifetime']);
  251. }
  252. }
  253. /**
  254. * @hooks
  255. * @hookdef hook-system-page_output 'system', 'page_output' - hook with page data to be output
  256. * - $unit_name - equals `system`
  257. * - $action - equals `page_output`
  258. * - $object_id - not used
  259. * - $sender_id - not used
  260. * - $extra_params - array of additional params with the following array keys:
  261. * - `page_name` - [string] page object name
  262. * - `page_object` - [object] an instance of page class, @see BxDolPage
  263. * - `page_query` - [object] an instance of page related query class
  264. * - `page_code` - [string] by ref, final page code to be output, can be overridden in hook processing
  265. * - `sub_page` - [boolean] if the page is used as subpage of some parent page
  266. * @hook @ref hook-system-page_output
  267. */
  268. bx_alert('system', 'page_output', 0, false, [
  269. 'page_name' => $this->_sObject,
  270. 'page_object' => $this,
  271. 'page_query' => $this->_oQuery,
  272. 'page_code' => &$sPageCode,
  273. 'sub_page' => $this->_bSubPage,
  274. ]);
  275. if (!$this->_bSubPage)
  276. $sPageCode .= $this->getJsScript();
  277. return $sPageCode;
  278. }
  279. public function getJsClassName()
  280. {
  281. return $this->_sJsClassName;
  282. }
  283. public function getJsObjectName()
  284. {
  285. return $this->_sJsObjectName;
  286. }
  287. function _wrapInTagJsCode($sCode)
  288. {
  289. return "<script language=\"javascript\">\n<!--\n" . $sCode . "\n-->\n</script>";
  290. }
  291. public function getJsScript()
  292. {
  293. $sJsObjName = $this->getJsObjectName();
  294. $sJsObjClass = $this->getJsClassName();
  295. $sCode = "if(window['" . $sJsObjName . "'] == undefined) var " . $sJsObjName . " = new " . $sJsObjClass . "(" . json_encode(array(
  296. 'sObjName' => $sJsObjName,
  297. 'sObject' => $this->_sObject,
  298. 'sRootUrl' => BX_DOL_URL_ROOT,
  299. 'aHtmlIds' => $this->_aHtmlIds,
  300. 'isStickyColumns' => $this->_bStickyColumns
  301. )) . ");";
  302. return $this->_wrapInTagJsCode($sCode);
  303. }
  304. /**
  305. * Is page cover enabled.
  306. * @return string
  307. */
  308. public function isPageCover()
  309. {
  310. $bResult = false;
  311. switch((int)$this->_aObject['cover']) {
  312. case 1: //--- Enabled for all
  313. $bResult = true;
  314. break;
  315. case 2: //--- Enabled for visitors only
  316. $bResult = !isLogged();
  317. break;
  318. case 3: //--- Enabled for members only
  319. $bResult = isLogged();
  320. break;
  321. }
  322. return $bResult;
  323. }
  324. public function setSubPage($b = true)
  325. {
  326. $this->_bSubPage = $b;
  327. }
  328. public function setPageCover($bCover = true)
  329. {
  330. $this->_aObject['cover'] = (bool)$bCover;
  331. }
  332. public function getPageCoverImage($bTranscoder = true)
  333. {
  334. $iId = (int)$this->_aObject['cover_image'];
  335. if(empty($iId)) {
  336. $iId = (int)getParam('sys_site_cover_common');
  337. if(empty($iId))
  338. return array();
  339. }
  340. $aResult = array(
  341. 'id' => $iId
  342. );
  343. if($bTranscoder)
  344. $aResult['transcoder'] = BX_DOL_TRANSCODER_OBJ_COVER;
  345. else
  346. $aResult['object'] = $this->_sStorage;
  347. return $aResult;
  348. }
  349. public function getPageCoverParams()
  350. {
  351. $aParams = [
  352. 'title' => $this->_getPageTitle(),
  353. 'actions' => '',
  354. 'bx_if:image' => [
  355. 'condition' => false,
  356. 'content' => []
  357. ],
  358. 'bx_if:icon' => [
  359. 'condition' => false,
  360. 'content' => []
  361. ],
  362. ];
  363. if(($oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu')) !== false) {
  364. $aCoverParams = $oMenuSubmenu->getPageCoverParams();
  365. if(!empty($aCoverParams) && is_array($aCoverParams))
  366. $aParams = $aCoverParams;
  367. }
  368. if(!empty($this->_aObject['cover_title'])) {
  369. $sCoverTitle = _t($this->_aObject['cover_title']);
  370. if($sCoverTitle && strcmp($sCoverTitle, $this->_aObject['cover_title']) != 0)
  371. $aParams['title'] = $sCoverTitle;
  372. }
  373. return $aParams;
  374. }
  375. /**
  376. * Get block title.
  377. * @return string
  378. */
  379. public function getBlockTitle ($aBlock)
  380. {
  381. return $this->_replaceMarkers(_t($aBlock['title']), array('block_id' => $aBlock['id']));
  382. }
  383. /**
  384. * Get help control if help is available for the block.
  385. * @return string
  386. */
  387. public function getBlockHelp ($aBlock)
  388. {
  389. if(empty($aBlock['help']) || empty(strip_tags(_t($aBlock['help']))))
  390. return '';
  391. return $this->_oTemplate->parseHtmlByName('designbox_help.html', array(
  392. 'js_object' => $this->_sJsObjectName,
  393. 'block_id' => $aBlock['id']
  394. ));
  395. }
  396. /**
  397. * Get code to load block asyncroniously
  398. * @param $aBlock block code
  399. * @param $iAsync if greater than 0 the it defines loading indicator for the block
  400. * @return HTML code string
  401. */
  402. public function getBlockAsyncCode($aBlock, $iAsync)
  403. {
  404. $aContentPlaceholder = $this->_oQuery->getPageBlockContentPlaceholder($iAsync);
  405. if (!$aContentPlaceholder)
  406. return _t('_sys_txt_error_occured');
  407. $oTemplate = $this->_oTemplate;
  408. if ('system' != $aContentPlaceholder['module']) {
  409. $oModule = BxDolModule::getInstance($aContentPlaceholder['module']);
  410. if (!$oModule)
  411. return _t('_sys_txt_error_occured');
  412. $oTemplate = $oModule->_oTemplate;
  413. }
  414. return $oTemplate->parseHtmlByName($aContentPlaceholder['template'], $aBlock);
  415. }
  416. /**
  417. * Get page array with all cells and blocks
  418. */
  419. public function getPageAPI ($aBlocks = [])
  420. {
  421. define('BX_API_PAGE', true);
  422. $query_string = '';
  423. if (isset(bx_get('params')[2]) && bx_get('params')[2] != ''){
  424. $array = json_decode(bx_get('params')[2], true);
  425. $query_string = http_build_query($array);
  426. parse_str($query_string, $a);
  427. $_GET = array_merge($_GET, $a);
  428. }
  429. $bIsAvailable = $this->_isAvailablePage($this->_aObject);
  430. $bIsVisible = $this->_isVisiblePage($this->_aObject);
  431. //TODO: If page isn't Available or isn't Visible then we should exit with related Error Codes immediately.
  432. $sMetaTitle = $this->_getPageMetaTitle();
  433. $sName = $this->_getPageTitle();
  434. $a = [
  435. 'id' => $this->_aObject['id'],
  436. 'title' => $sMetaTitle ? $sMetaTitle : $sName,
  437. 'name' => $sName,
  438. 'description' => $this->_getPageMetaDesc(),
  439. 'keywords' => $this->_getPageMetaKeywords(),
  440. 'image' => '',
  441. 'uri' => $this->_aObject['uri'],
  442. 'url' => ((bx_get('params')[0] ? bx_get('params')[0] : $this->_aObject['uri'] ) . ($query_string != '' ? '?' . $query_string : '')),
  443. 'author' => $this->_aObject['author'],
  444. 'added' => $this->_aObject['added'],
  445. 'module' => $this->getModule(),
  446. 'type' => $this->getType (),
  447. 'layout' => str_replace('.html', '', $this->_aObject['template']),
  448. 'cover_block' => '',
  449. 'menu_top' => '',
  450. 'menu' => '',
  451. 'menu_bottom' => '',
  452. 'menu_add' => '',
  453. 'config' => $this->_aObject['config_api'],
  454. 'elements' => $this->getPageBlocksAPI($aBlocks),
  455. ];
  456. $sMenuTop = getParam('sys_api_menu_top');
  457. if (!empty($sMenuTop) && ($oMenuTop = BxDolMenu::getObjectInstance($sMenuTop)) !== false)
  458. $a['menu_top'] = $oMenuTop->getCodeAPI();
  459. if (($oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu')) !== false) {
  460. if(($sSubmenu = $this->getSubMenu()) !== '')
  461. $oMenuSubmenu->setObjectSubmenu($sSubmenu, []);
  462. $a['menu'] = $oMenuSubmenu->getCodeAPI();
  463. }
  464. /**
  465. * Profile/Context view page.
  466. */
  467. if(isset($this->_aProfileInfo)) {
  468. $oProfileModule = BxDolModule::getInstance($this->_aProfileInfo['type']);
  469. if($oProfileModule !== null)
  470. $aProfileContentInfo = $oProfileModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
  471. if(!empty($aProfileContentInfo) && is_array($aProfileContentInfo)) {
  472. $CNF = &$oProfileModule->_oConfig->CNF;
  473. /**
  474. * Process page cover with related menus and lists.
  475. */
  476. if(BxDolCover::getInstance($this)->isCover()) {
  477. $aProfileInfo = BxDolProfile::getData($this->_aProfileInfo['id'], [
  478. 'get_avatar' => 'getAvatarBig',
  479. 'with_info' => true
  480. ]);
  481. $oProfile = BxDolProfile::getInstance($this->_aProfileInfo['id']);
  482. $aProfileInfo['online'] = $oProfile->isOnline();
  483. unset($aProfileInfo['info']['profile_email']);
  484. unset($aProfileInfo['info']['profile_last_active']);
  485. unset($aProfileInfo['info']['profile_ip']);
  486. $a['cover_block'] = [
  487. 'profile' => $aProfileInfo,
  488. 'actions_menu' => '',
  489. 'meta_menu' => '',
  490. 'badges' => $oProfile->getBadges(),
  491. 'cover' => $oProfileModule->serviceGetCover($this->_aProfileInfo['content_id']),
  492. 'allow_edit' => $oProfileModule->checkAllowedChangeCover($aProfileContentInfo) === CHECK_ACTION_RESULT_ALLOWED
  493. ];
  494. if(!empty($CNF['OBJECT_MENU_VIEW_ENTRY_META']) && ($oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META'])) !== false)
  495. $a['cover_block']['meta_menu'] = $oMetaMenu->getCodeAPI();
  496. if(!empty($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) !== false)
  497. $a['cover_block']['members_list'] = $oConnection->getConnectedListAPI($this->_aProfileInfo['id'], false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 10);
  498. if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']) && ($oActionMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'])) !== false)
  499. $a['cover_block']['actions_menu'] = $oActionMenu->getCodeAPI();
  500. }
  501. /**
  502. * Process page mange menu.
  503. */
  504. if(($oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage')) !== false) {
  505. if(!empty($CNF['FIELD_ID']))
  506. $oMenuManage->setContentId($aProfileContentInfo[$CNF['FIELD_ID']]);
  507. $aObjectManage = [];
  508. if(!empty($CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']))
  509. $aObjectManage = [$CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']];
  510. else if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  511. $aObjectManage = [$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE'], true];
  512. call_user_func_array([$oMenuManage, 'setObjectManage'], $aObjectManage);
  513. $aMenuManage = $oMenuManage->getCodeAPI();
  514. if(!empty($aMenuManage) && is_array($aMenuManage)) {
  515. if(isset($a['cover_block'], $a['cover_block']['actions_menu']) && is_array($a['cover_block']['actions_menu']))
  516. $a['cover_block']['actions_menu']['items'] = array_merge($a['cover_block']['actions_menu']['items'], $aMenuManage['items']);
  517. else
  518. $a['cover_block']['actions_menu'] = $aMenuManage;
  519. }
  520. }
  521. }
  522. }
  523. if (isLogged()) {
  524. $o = BxDolProfile::getInstance();
  525. $a['user'] = BxDolProfile::getDataForPage($o);
  526. }
  527. $aExtras = [
  528. 'page' => $this,
  529. 'blocks' => $aBlocks,
  530. 'data' => &$a,
  531. ];
  532. if(!$bIsAvailable)
  533. $a['page_status'] = 404;
  534. else if(!$bIsVisible)
  535. $a['page_status'] = 403;
  536. /**
  537. * @hooks
  538. * @hookdef hook-system-get_page_api 'system', 'get_page_api' - hook to override page peremeters, is used in API calls
  539. * - $unit_name - equals `system`
  540. * - $action - equals `get_page_api`
  541. * - $object_id - not used
  542. * - $sender_id - not used
  543. * - $extra_params - array of additional params with the following array keys:
  544. * - `page` - [object] an instance of page class, @see BxDolPage
  545. * - `blocks` - [array] array with page blocks
  546. * - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
  547. * @hook @ref hook-system-get_page_api
  548. */
  549. bx_alert('system', 'get_page_api', 0, 0, $aExtras);
  550. return $a;
  551. }
  552. public function getPageBlocksAPI($aBlocks = [])
  553. {
  554. $bBlocks = !empty($aBlocks) && is_array($aBlocks);
  555. $aFieldsUnset = ['object', 'cell_id', 'title_system', 'class', 'submenu', 'tabs', 'async', 'visible_for_levels', 'hidden_on', 'type', 'text', 'text_updated', 'help', 'cache_lifetime', 'active', 'active_api', 'copyable', 'deletable', 'order'];
  556. $aCells = $this->_oQuery->getPageBlocks(true);
  557. foreach($aCells as $sKey => &$aCell) {
  558. foreach($aCell as $i => $aBlock) {
  559. if(!$this->_isVisibleBlock($aBlock)) {
  560. unset($aCells[$sKey][$i]);
  561. continue;
  562. }
  563. $this->processPageBlock($aCells[$sKey][$i], true);
  564. $aBlock = $aCells[$sKey][$i];
  565. $sSource = '';
  566. if($aBlock['type'] == 'service') {
  567. $aContent = @unserialize($aBlock['content']);
  568. if(isset($aContent['module'], $aContent['method']))
  569. $sSource = $aContent['module'] . ':' . $aContent['method'];
  570. }
  571. else
  572. $sSource = 'system:block_' . $aBlock['id'];
  573. if($bBlocks && !in_array($sSource, $aBlocks)) {
  574. unset($aCells[$sKey][$i]);
  575. continue;
  576. }
  577. $mBlock = $aBlock['content'];
  578. if(($sFunc = '_getBlock' . bx_gen_method_name($aBlock['type'])) && method_exists($this, $sFunc))
  579. $mBlock = $this->$sFunc($aBlock);
  580. if(empty($mBlock)) {
  581. unset($aCells[$sKey][$i]);
  582. continue;
  583. }
  584. $aCells[$sKey][$i] = array_merge($aCells[$sKey][$i], [
  585. 'title' => isset($mBlock['title']) ? $mBlock['title'] : $this->getBlockTitle($aBlock),
  586. 'content' => isset($mBlock['content']) ? $mBlock['content'] : $mBlock,
  587. 'menu' => isset($mBlock['menu']) ? $mBlock['menu'] : '',
  588. 'source' => $sSource
  589. ]);
  590. $aCells[$sKey][$i] = array_diff_key($aCells[$sKey][$i], array_flip($aFieldsUnset));
  591. }
  592. }
  593. return array_map('array_values', $aCells);
  594. }
  595. /**
  596. * Get page code vars
  597. * @return string
  598. */
  599. protected function _getPageCodeVars ()
  600. {
  601. $aHiddenOn = array(
  602. pow(2, BX_DB_HIDDEN_PHONE - 1) => 'bx-def-media-phone-hide',
  603. pow(2, BX_DB_HIDDEN_TABLET - 1) => 'bx-def-media-tablet-hide',
  604. pow(2, BX_DB_HIDDEN_DESKTOP - 1) => 'bx-def-media-desktop-hide',
  605. pow(2, BX_DB_HIDDEN_MOBILE - 1) => 'bx-def-mobile-app-hide'
  606. );
  607. $aVars = array (
  608. 'page_id' => 'bx-page-' . $this->_aObject['uri'],
  609. 'bx_if:show_layout_row_dump' => array(
  610. 'condition' => false,
  611. 'content' => array()
  612. )
  613. );
  614. $aBlocks = $this->_oQuery->getPageBlocks();
  615. foreach ($aBlocks as $sKey => $aCell) {
  616. $sCell = '';
  617. foreach ($aCell as $aBlock) {
  618. $this->processPageBlock($aBlock, false);
  619. $sContentWithBox = $this->_getBlockCodeWithCache($aBlock, $aBlock['async']);
  620. $sClassAdd = '';
  621. if(!empty($aBlock['class']))
  622. $sClassAdd .= ' ' . $aBlock['class'];
  623. if(!empty($aBlock['hidden_on']))
  624. foreach($aHiddenOn as $iHiddenOn => $sHiddenOnClass)
  625. if((int)$aBlock['hidden_on'] & $iHiddenOn)
  626. $sClassAdd .= ' ' . $sHiddenOnClass;
  627. if ($sContentWithBox)
  628. $sCell .= $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
  629. 'class_add' => $sClassAdd,
  630. 'bx_if:show_html_id' => array(
  631. 'condition' => true,
  632. 'content' => array(
  633. 'html_id' => 'bx-page-block-' . $aBlock['id']
  634. ),
  635. ),
  636. 'content' => $sContentWithBox
  637. ));
  638. }
  639. $aVars[$sKey] = $sCell;
  640. }
  641. return $aVars;
  642. }
  643. /**
  644. * Process block values, especially if someting need to be overrided
  645. */
  646. protected function processPageBlock(&$aBlock, $bApi = false)
  647. {
  648. }
  649. /**
  650. * Get page code only.
  651. * @return string
  652. */
  653. protected function _getPageCode ()
  654. {
  655. $aVars = $this->_getPageCodeVars ();
  656. return $this->_oTemplate->parseHtmlByName($this->_aObject['template'], $aVars);
  657. }
  658. /**
  659. * Get one block code only.
  660. * @return string
  661. */
  662. protected function _getBlockOnlyCode ($iBlockId)
  663. {
  664. if (!($aBlock = $this->_oQuery->getPageBlock((int)$iBlockId)))
  665. return '';
  666. return $this->_getBlockCodeWithCache($aBlock, 0);
  667. }
  668. protected function _getBlockCodeWithCache(&$aBlock, $iAsync = 0)
  669. {
  670. if (bx_is_dbg() || !getParam('sys_pb_cache_enable') || !$aBlock['cache_lifetime'] || $iAsync || (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST')) {
  671. $sBlockCode = $this->_getBlockCode($aBlock, $iAsync);
  672. }
  673. else {
  674. $oCache = $this->_getBlockCacheObject();
  675. $sKey = $this->_getBlockCacheKey(false, $aBlock);
  676. $sKeyCssJs = 'cssjs_' . $sKey;
  677. $mixedRet = $oCache->getData($sKey, $aBlock['cache_lifetime']);
  678. $aRetCssJs = $oCache->getData($sKeyCssJs, $aBlock['cache_lifetime']);
  679. if ($mixedRet !== null && $aRetCssJs !== null) {
  680. BxDolTemplate::getInstance()->collectingStart();
  681. BxDolTemplate::getInstance()->collectingInject($aRetCssJs['css'], $aRetCssJs['js']);
  682. $sBlockCode = BxDolTemplate::getInstance()->collectingEndGetCode();
  683. $sBlockCode .= $mixedRet;
  684. } else {
  685. BxDolTemplate::getInstance()->collectingStart();
  686. $sBlockCode = $this->_getBlockCode($aBlock, $iAsync);
  687. $aBlockCssJs = BxDolTemplate::getInstance()->collectingEndGetCode(array(), array(), 'array');
  688. $oCache->setData($sKey, $sBlockCode, $aBlock['cache_lifetime']);
  689. $oCache->setData($sKeyCssJs, $aBlockCssJs, $aBlock['cache_lifetime']);
  690. }
  691. }
  692. return $sBlockCode;
  693. }
  694. /**
  695. * Get block code.
  696. * @return string
  697. */
  698. protected function _getBlockCode(&$aBlock, $iAsync = 0)
  699. {
  700. $sContentWithBox = '';
  701. $oFunctions = $this->_oTemplate->getTemplateFunctions();
  702. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPageBlock(_t($aBlock['title']), $aBlock['id']);
  703. $aDbNoTitle = [BX_DB_CONTENT_ONLY, BX_DB_PADDING_CONTENT_ONLY, BX_DB_NO_CAPTION, BX_DB_PADDING_NO_CAPTION];
  704. $sTitle = $this->getBlockTitle($aBlock);
  705. $sHelp = $this->getBlockHelp($aBlock);
  706. $sFunc = '_getBlock' . ucfirst($aBlock['type']);
  707. $bBlockVisible = $this->_isVisibleBlock($aBlock);
  708. if ($iAsync && $bBlockVisible) {
  709. $iDesignboxId = $aBlock['designbox_id'];
  710. $sHelpTitle = $sHelpContent = '';
  711. if(!in_array($iDesignboxId, $aDbNoTitle))
  712. $sHelpTitle = $sHelp;
  713. else
  714. $sHelpContent = $sHelp;
  715. $sContent = $this->getBlockAsyncCode($aBlock, $iAsync);
  716. $aParams = array(
  717. $sTitle . $sHelpTitle,
  718. $sContent . $sHelpContent,
  719. $iDesignboxId
  720. );
  721. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  722. }
  723. elseif ($bBlockVisible && method_exists($this, $sFunc)) {
  724. $mixedContent = $this->$sFunc($aBlock);
  725. if(!empty($aBlock['content_empty'])) {
  726. $sEmpty = _t($aBlock['content_empty']);
  727. $sRegExp = '/(<[A-Za-z0-9]+\b.[^<]*[\pPi\pPf]bx\-msg\-box\b.*[\pPi\pPf][^>]*>)(' . _t('_Empty') . ')(<\/[A-Za-z0-9]+>)/su';
  728. if(is_string($mixedContent))
  729. $mixedContent = preg_replace($sRegExp, "\${1}" . $sEmpty . "\${3}", $mixedContent);
  730. else if(is_array($mixedContent) && !empty($mixedContent['content']))
  731. $mixedContent['content'] = preg_replace($sRegExp, "\${1}" . $sEmpty . "\${3}", $mixedContent['content']);
  732. }
  733. $this->_oQuery->setReadOnlyMode(true);
  734. if(is_array($mixedContent) && !empty($mixedContent['content'])) {
  735. $iDesignboxId = isset($mixedContent['designbox_id']) ? $mixedContent['designbox_id'] : $aBlock['designbox_id'];
  736. if(!empty($mixedContent['markers']) && is_array($mixedContent['markers'])) {
  737. $this->addMarkers($mixedContent['markers']);
  738. $sTitle = $this->getBlockTitle($aBlock);
  739. }
  740. $sHelpTitle = $sHelpContent = '';
  741. if(!in_array($iDesignboxId, $aDbNoTitle))
  742. $sHelpTitle = $sHelp;
  743. else
  744. $sHelpContent = $sHelp;
  745. $aParams = array(
  746. (isset($mixedContent['title']) ? $mixedContent['title'] : $sTitle) . $sHelpTitle,
  747. $mixedContent['content'] . $sHelpContent,
  748. $iDesignboxId
  749. );
  750. $mixedMenu = false;
  751. if(isset($mixedContent['menu']))
  752. $mixedMenu = $mixedContent['menu'];
  753. else if(!empty($aBlock['submenu']))
  754. $mixedMenu = $aBlock['submenu'];
  755. $aParams[] = $mixedMenu;
  756. if(isset($mixedContent['buttons']))
  757. $aParams[] = $mixedContent['buttons'];
  758. else if($mixedMenu)
  759. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  760. if(isset($mixedContent['class']))
  761. $aBlock['class'] = $mixedContent['class'];
  762. }
  763. else if(is_string($mixedContent) && !empty($mixedContent)) {
  764. $iDesignboxId = $aBlock['designbox_id'];
  765. $sHelpTitle = $sHelpContent = '';
  766. if(!in_array($iDesignboxId, $aDbNoTitle))
  767. $sHelpTitle = $sHelp;
  768. else
  769. $sHelpContent = $sHelp;
  770. $aParams = array(
  771. $sTitle . $sHelpTitle,
  772. $mixedContent . $sHelpContent,
  773. $iDesignboxId
  774. );
  775. $mixedMenu = !empty($aBlock['submenu']) ? $aBlock['submenu'] : false;
  776. $aParams[] = $mixedMenu;
  777. if($mixedMenu)
  778. $aParams[] = (int)$aBlock['tabs'] == 1 ? true : array();
  779. }
  780. if(!empty($aParams))
  781. $sContentWithBox = call_user_func_array(array($oFunctions, 'designBoxContent'), $aParams);
  782. }
  783. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPageBlock($aBlock['id'], $sContentWithBox ? false : true, false );
  784. return $sContentWithBox;
  785. }
  786. /**
  787. * Add necessary js and css files.
  788. */
  789. protected function _addJsCss()
  790. {
  791. $this->_oTemplate->addJs(array('BxDolPage.js', 'theia-sticky-sidebar/theia-sticky-sidebar.min.js', 'theia-sticky-sidebar/ResizeSensor.min.js'));
  792. $this->_oTemplate->addCss('page_layouts.css');
  793. }
  794. /**
  795. * Set system template variables, like page title, meta description, meta keywords and meta robots.
  796. */
  797. protected function _addSysTemplateVars ()
  798. {
  799. $oTemplate = BxDolTemplate::getInstance();
  800. $sPageTitle = $this->_getPageTitle();
  801. if ($sPageTitle)
  802. $oTemplate->setPageHeader ($sPageTitle);
  803. $sMetaTitle = $this->_getPageMetaTitle();
  804. if ($sMetaTitle)
  805. $oTemplate->setPageMetaTitle ($sMetaTitle);
  806. $sMetaDesc = $this->_getPageMetaDesc();
  807. if ($sMetaDesc)
  808. $oTemplate->setPageDescription ($sMetaDesc);
  809. $sMetaRobots = $this->_getPageMetaRobots();
  810. if ($sMetaRobots)
  811. $oTemplate->setPageMetaRobots ($sMetaRobots);
  812. $sMetaImage = $this->_getPageMetaImage();
  813. if ($sMetaImage)
  814. $oTemplate->addPageMetaImage($sMetaImage);
  815. $sMetaKeywords = $this->_getPageMetaKeywords();
  816. if ($sMetaKeywords)
  817. $oTemplate->addPageKeywords ($sMetaKeywords);
  818. }
  819. /**
  820. * Select menu from page properties.
  821. */
  822. protected function _selectMenu ()
  823. {
  824. BxDolMenu::setSelectedGlobal ($this->_aObject['module'], $this->_aObject['uri']);
  825. }
  826. /**
  827. * Set page submenu if it's specified
  828. */
  829. protected function _setSubmenu ($aParams)
  830. {
  831. if(empty($this->_aObject['submenu']) || $this->_aObject['submenu'] == 'disabled')
  832. return;
  833. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  834. if(!$oMenuSubmenu)
  835. return;
  836. $oMenuSubmenu->setObjectSubmenu($this->_aObject['submenu'], $aParams);
  837. }
  838. /**
  839. * Get content for 'raw' block type.
  840. * @return string
  841. */
  842. protected function _getBlockRaw ($aBlock)
  843. {
  844. if (bx_is_api()){
  845. return [bx_api_get_block('raw', ['title' => _t($aBlock['title']), 'content' => BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array())])];
  846. }
  847. $s = '<div class="bx-page-raw-container bx-def-vanilla-html max-w-none">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  848. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  849. $s = bx_process_macros($s);
  850. return $s;
  851. }
  852. /**
  853. * Get content for 'custom' block type.
  854. * @return string
  855. */
  856. protected function _getBlockCustom ($aBlock)
  857. {
  858. if (bx_is_api()){
  859. return [bx_api_get_block('custom', ['title' => _t($aBlock['title']), 'content' => BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array())])];
  860. }
  861. $s = '<div class="bx-page-custom-container">' . BxDolTemplate::getInstance()->parseHtmlByContent($aBlock['content'], array()) . '</div>';
  862. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  863. $s = bx_process_macros($s);
  864. return $s;
  865. }
  866. /**
  867. * Get content for 'html' block type.
  868. * @return string
  869. */
  870. protected function _getBlockHtml ($aBlock)
  871. {
  872. if (bx_is_api()){
  873. return [bx_api_get_block('html', ['title' => _t($aBlock['title']), 'content' => $aBlock['content']])];
  874. }
  875. $s = '<div class="bx-page-html-container bx-def-vanilla-html max-w-none">' . $aBlock['content'] . '</div>';
  876. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  877. $s = bx_process_macros($s);
  878. return $s;
  879. }
  880. /**
  881. * Get content for 'creative' block type.
  882. * @return string
  883. */
  884. protected function _getBlockCreative ($aBlock)
  885. {
  886. if(bx_is_api())
  887. return [bx_api_get_block('creative', ['title' => _t($aBlock['title']), 'content' => $aBlock['content']])];
  888. $s = $this->_replaceMarkers($aBlock['content'], ['block_id' => $aBlock['id']]);
  889. $s = bx_process_macros($s);
  890. $bCanManage = $this->isAllowedCreativeManage();
  891. if($bCanManage) {
  892. $this->_oTemplate->addCss([
  893. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'grapesjs/|grapes.min.css',
  894. ]);
  895. $this->_oTemplate->addJs([
  896. 'grapesjs/grapes.min.js',
  897. 'grapesjs/grapesjs-blocks-basic.js',
  898. 'grapesjs/grapesjs-style-bg.js',
  899. 'grapesjs/grapesjs-preset-webpage.min.js',
  900. ]);
  901. }
  902. return $this->_oTemplate->parseHtmlByName('block_creative.html', [
  903. 'block_id' => $aBlock['id'],
  904. 'content' => $s,
  905. 'bx_if:show_controls' => [
  906. 'condition' => $bCanManage,
  907. 'content' => [
  908. 'onclick_edit' => $this->_sJsObjectName . '.creativeEdit(this, ' . $aBlock['id'] . ')',
  909. 'onclick_save' => $this->_sJsObjectName . '.creativeSave(this, ' . $aBlock['id'] . ')'
  910. ]
  911. ]
  912. ]);
  913. }
  914. /**
  915. * Get content for 'bento_grid' block type.
  916. * @return string
  917. */
  918. protected function _getBlockBentoGrid ($aBlock)
  919. {
  920. if(bx_is_api()) {
  921. $iBlockId = (int)$aBlock['id'];
  922. $iContentId = 0;
  923. if(($mContentId = bx_get('id')) !== false)
  924. $iContentId = (int)$mContentId;
  925. $sContentModule = '';
  926. if(!empty($this->_aObject['module']) && !in_array($this->_aObject['module'], ['system', 'custom']))
  927. $sContentModule = $this->_aObject['module'];
  928. $bIsAllowedEdit = false;
  929. if(!empty($sContentModule) && bx_is_srv($sContentModule, 'check_allowed_with_content'))
  930. $bIsAllowedEdit = bx_srv($sContentModule, 'check_allowed_with_content', ['edit', $iContentId]) === CHECK_ACTION_RESULT_ALLOWED;
  931. else
  932. $bIsAllowedEdit = isAdmin();
  933. return [bx_api_get_block('bento_grid', [
  934. 'title' => _t($aBlock['title']),
  935. 'content' => self::getPageBlockData($iBlockId, $iContentId, $sContentModule)
  936. ], ['ext' => [
  937. 'block_id' => $iBlockId,
  938. 'content_id' => $iContentId,
  939. 'content_module' => $sContentModule,
  940. 'is_allowed_edit' => $bIsAllowedEdit
  941. ]])];
  942. }
  943. /**
  944. * Isn't supported for now.
  945. */
  946. return '';
  947. }
  948. /**
  949. * Get content for 'wiki' block type.
  950. * @return string
  951. */
  952. protected function _getBlockWiki ($aBlock)
  953. {
  954. $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
  955. if (!$oWiki) {
  956. $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
  957. }
  958. else {
  959. $sContent = $oWiki->getBlockContent($aBlock['id'], false, (int)bx_get($aBlock['id'].'rev') ? (int)bx_get($aBlock['id'].'rev') : false);
  960. }
  961. $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container markdown-body bx-def-vanilla-html">' . $sContent . '</div>';
  962. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  963. $s = bx_process_macros($s);
  964. return $s;
  965. }
  966. /**
  967. * Get content for 'lang' block type.
  968. * @return string
  969. */
  970. protected function _getBlockLang ($aBlock)
  971. {
  972. if (bx_is_api()){
  973. return [bx_api_get_block('lang', ['title' => _t($aBlock['title']), 'content' => bx_process_macros(_t(trim($aBlock['content'])))])];
  974. }
  975. $s = '<div class="bx-page-lang-container bx-def-vanilla-html max-w-none">' . _t(trim($aBlock['content'])) . '</div>';
  976. $s = $this->_replaceMarkers($s, array('block_id' => $aBlock['id']));
  977. $s = bx_process_macros($s);
  978. return $s;
  979. }
  980. /**
  981. * Get content for 'image' block type.
  982. * @return string
  983. */
  984. protected function _getBlockImage ($aBlock)
  985. {
  986. if (empty($aBlock['content']))
  987. return false;
  988. list($iFileId, $sAlign ) = explode('#', $aBlock['content']);
  989. $iFileId = (int)$iFileId;
  990. if (!$iFileId)
  991. return false;
  992. $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  993. if (!$oStorage)
  994. return false;
  995. $sUrl = $oStorage->getFileUrlById($iFileId);
  996. if (!$sUrl)
  997. return false;
  998. $sStyleAdd = '';
  999. $sClassAdd = 'bx-page-image-container';
  1000. $aAlign = ['left' => 'start', 'center' => 'center', 'right' => 'end'];
  1001. if(array_key_exists($sAlign, $aAlign)) {
  1002. $sClassAdd .= ' flex justify-' . $aAlign[$sAlign];
  1003. $sStyleAdd = 'style="text-align:' . $sAlign . '"';
  1004. }
  1005. return '<div class="' . $sClassAdd . '" ' . $sStyleAdd . '><img src="' . $sUrl . '" /></div>';
  1006. }
  1007. /**
  1008. * Get content for 'rss' block type.
  1009. * @return string
  1010. */
  1011. protected function _getBlockRss ($aBlock)
  1012. {
  1013. if (empty($aBlock['content']))
  1014. return false;
  1015. list( $sUrl, $iNum ) = explode('#', $aBlock['content']);
  1016. $iNum = (int)$iNum;
  1017. return BxDolRss::getObjectInstance('sys_page_block')->getHolder($aBlock['id'], $iNum);
  1018. }
  1019. /**
  1020. * Get content for 'menu' block type.
  1021. * @return string
  1022. */
  1023. protected function _getBlockMenu ($aBlock)
  1024. {
  1025. $oMenu = BxTemplMenu::getObjectInstance($aBlock['content']);
  1026. return $oMenu ? $oMenu->getCode () : '';
  1027. }
  1028. /**
  1029. * Get content for 'service' block type.
  1030. * @return string
  1031. */
  1032. protected function _getBlockService ($aBlock)
  1033. {
  1034. $aMarkers = array_merge($this->_aMarkers, [
  1035. 'block_id' => $aBlock['id']
  1036. ]);
  1037. return BxDolService::callSerialized($aBlock['content'], $aMarkers);
  1038. }
  1039. /**
  1040. * Get page title.
  1041. * @return string
  1042. */
  1043. protected function _getPageTitle()
  1044. {
  1045. return $this->_replaceMarkers(_t($this->_aObject['title']));
  1046. }
  1047. /**
  1048. * Get page meta description.
  1049. * @return string
  1050. */
  1051. protected function _getPageMetaDesc()
  1052. {
  1053. return $this->_replaceMarkers(_t($this->_aObject['meta_description']));
  1054. }
  1055. /**
  1056. * Get page meta title.
  1057. * @return string
  1058. */
  1059. protected function _getPageMetaTitle()
  1060. {
  1061. return $this->_replaceMarkers(_t($this->_aObject['meta_title']));
  1062. }
  1063. /**
  1064. * Get page meta image.
  1065. * @return string
  1066. */
  1067. protected function _getPageMetaImage()
  1068. {
  1069. return '';
  1070. }
  1071. /**
  1072. * Get page meta keywords.
  1073. * @return string
  1074. */
  1075. protected function _getPageMetaKeywords()
  1076. {
  1077. return $this->_replaceMarkers(_t($this->_aObject['meta_keywords']));
  1078. }
  1079. /**
  1080. * Get page meta robots.
  1081. * @return string
  1082. */
  1083. protected function _getPageMetaRobots()
  1084. {
  1085. return _t($this->_aObject['meta_robots']);
  1086. }
  1087. /**
  1088. * Get page not found message.
  1089. * @return string
  1090. */
  1091. protected function _getPageNotFoundMsg ($mixedMsg = false)
  1092. {
  1093. $this->_oTemplate->displayPageNotFound();
  1094. exit;
  1095. }
  1096. /**
  1097. * Get access denied message.
  1098. * @return string
  1099. */
  1100. protected function _getPageAccessDeniedMsg ($mixedMsg = false)
  1101. {
  1102. return MsgBox($mixedMsg !== false ? $mixedMsg : _t('_Access denied'));
  1103. }
  1104. /**
  1105. * Get page cache object.
  1106. * @return cache object instance
  1107. */
  1108. protected function _getPageCacheObject ()
  1109. {
  1110. return $this->_getCacheObject ();
  1111. }
  1112. /**
  1113. * Get block cache object.
  1114. * @return cache object instance
  1115. */
  1116. protected function _getBlockCacheObject ()
  1117. {
  1118. return $this->_getCacheObject ('Block', 'pb');
  1119. }
  1120. protected function _getCacheObject ($sSuffixObj = 'Page', $sSuffixParam = 'page')
  1121. {
  1122. $sObj = '_o' . $sSuffixObj . 'CacheObject';
  1123. $sParam = 'sys_' . $sSuffixParam . '_cache_engine';
  1124. if ($this->{$sObj} != null) {
  1125. return $this->{$sObj};
  1126. } else {
  1127. $sEngine = getParam($sParam);
  1128. $this->{$sObj} = bx_instance ('BxDolCache' . $sEngine);
  1129. if (!$this->{$sObj}->isAvailable())
  1130. $this->{$sObj} = bx_instance ('BxDolCacheFile');
  1131. return $this->{$sObj};
  1132. }
  1133. }
  1134. /**
  1135. * Get page cache key.
  1136. * @param $isPrefixOnly return key prefix only.
  1137. * @return string
  1138. */
  1139. protected function _getPageCacheKey ($isPrefixOnly = false)
  1140. {
  1141. $s = 'page_' . $this->_aObject['object'] . '_';
  1142. if ($isPrefixOnly)
  1143. return $s;
  1144. $s .= $this->_getPageCacheParams ();
  1145. $s .= bx_site_hash() . '.php';
  1146. return $s;
  1147. }
  1148. /**
  1149. * Get block cache key.
  1150. * @param $isPrefixOnly return key prefix only.
  1151. * @return string
  1152. */
  1153. protected function _getBlockCacheKey ($isPrefixOnly = false, $aBlock = array())
  1154. {
  1155. $s = $this->_getPageCacheKey(true) . 'block_';
  1156. if ($isPrefixOnly)
  1157. return $s;
  1158. $s .= ($aBlock ? $aBlock['id'] : 0) . '_' . $this->_getPageCacheParams ();
  1159. $s .= bx_site_hash() . '.php';
  1160. return $s;
  1161. }
  1162. /**
  1163. * Additional cache key. In the case of dynamic page.
  1164. * For example - profile page, where each profile has own page.
  1165. * @return string
  1166. */
  1167. protected function _getPageCacheParams ()
  1168. {
  1169. return md5(serialize($_GET) . bx_lang_name());
  1170. }
  1171. /**
  1172. * Clean page cache.
  1173. * @param $isDelAllWithPagePrefix delete cache by prefix, it can be used for dynamic pages, like profile view, where for each profile separate cache is generated.
  1174. * @return string
  1175. */
  1176. protected function cleanCache ($isDelAllWithPagePrefix = false)
  1177. {
  1178. $a = ['Page', 'Block'];
  1179. $bRet = false;
  1180. foreach ($a as $s) {
  1181. $oCache = $this->{'_get' . $s . 'CacheObject'} ();
  1182. $sKey = $this->{'_get'. $s . 'CacheKey'} ($isDelAllWithPagePrefix);
  1183. if ($isDelAllWithPagePrefix)
  1184. $bRet = $bRet && $oCache->removeAllByPrefix($sKey);
  1185. else
  1186. $bRet = $bRet && $oCache->delData($sKey);
  1187. }
  1188. return $bRet;
  1189. }
  1190. }
  1191. /** @} */