BxDolPage.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. /**
  10. * Pages.
  11. *
  12. * It allows to display pages which are built from studio.
  13. *
  14. * The new system has the following page features:
  15. * - Layouts: page can have any structure, not just columns.
  16. * - SEO: page can have own SEO options, like meta tags and meta keywords, as well as instructions for search bots.
  17. * - Cache: page can be cached on the server.
  18. * - Access control: page access can be controlled using member levels.
  19. *
  20. *
  21. *
  22. * @section page_create Creating the Page object:
  23. *
  24. * 1. add record to 'sys_objects_page' table:
  25. *
  26. * - object: name of the page object, in the format: vendor prefix, underscore, module prefix, underscore, internal identifier or nothing; for example: bx_profiles_view - profile view page.
  27. * - title: name to display as page title.
  28. * - module: the module this page belongs to.
  29. * - layout_id: page layout to use, this is id of the record from 'sys_pages_layouts' table.
  30. * - visible_for_levels: bit field with set of member level ids. To use member level id in bit field - the level id minus 1 as power of 2 is used, for example:
  31. * - user level id = 1 -> 2^(1-1) = 1
  32. * - user level id = 2 -> 2^(2-1) = 2
  33. * - user level id = 3 -> 2^(3-1) = 4
  34. * - user level id = 4 -> 2^(4-1) = 8
  35. * - visible_for_levels_editable: it determines if 'visible_for_levels' field is editable from page builder, visibility options can be overriden by custom class and shouldn't be editable in this case.
  36. * - url: the page url, if it is static page.
  37. * - content_info: content info object name related to the content on the page,
  38. * if different from module name
  39. * - meta_description: meta description of the page.
  40. * - meta_keywords: meta keywords of the page.
  41. * - meta_robots: instructions for search bots.
  42. * - cache_lifetime: number of seconds to store cache for.
  43. * - cache_editable: it determines if cache can be edited from page builder.
  44. * - deletable: it determines if page can be deleted from page builder.
  45. * - override_class_name: user defined class name which is derived from BxTemplPage.
  46. * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
  47. *
  48. * Page can select appropriate menu automatically if 'module' and 'object' fields in 'sys_objects_page' table are matched with 'module' and 'name' fields in 'sys_menu_items' table.
  49. *
  50. *
  51. * Page layout are stored in 'sys_pages_layouts' table:
  52. * - name: inner unique layout name.
  53. * - icon: layout icon to display in page builder, it should represent basic view of the layout to help studio operator determine the layout structure.
  54. * - title: layout name to display in page builder.
  55. * - template: template name to use to display page with certain layout.
  56. * - cells_number: number of areas in the layout, page blocks can be places into this areas(cells).
  57. * To define areas in the layout they should be named as '__cell_N__', where N is cell number, starting from 1.
  58. *
  59. *
  60. * 2. Add page blocks to 'sys_pages_blocks' table:
  61. * - object: page object name this block belongs to.
  62. * - cell_id: cell number in page layout to place block to.
  63. * - module: module name this block belongs to.
  64. * - title: block title.
  65. * - designbox_id: design box to use to diplay page block, it is id of the record from 'sys_pages_design_boxes' table.
  66. * - visible_for_levels: bit field with set of member level ids. To use member level id in bit field - the level id minus 1 as power of 2 is used, for example:
  67. * - user level id = 1 -> 2^(1-1) = 1
  68. * - user level id = 2 -> 2^(2-1) = 2
  69. * - user level id = 3 -> 2^(3-1) = 4
  70. * - user level id = 4 -> 2^(4-1) = 8
  71. * - type: block type
  72. * - raw: HTML block, displayed in page builder as HTML textarea.
  73. * - html: HTML block, displayed in page builder as visual editor, like TinyMCE.
  74. * - lang: translatable language string, displayed in page builder as editable language key.
  75. * - image: just an image, displayed in page builder as HTML upload form.
  76. * - rss: RSS block, displayed in page builder as editable URL to RSS resource, along with number of displayed items.
  77. * - menu: menu block, displayed as menu selector.
  78. * - service: to display block content, the provided service method is used.
  79. * - content: depending on 'type' field:
  80. * - raw: HTML string.
  81. * - html: HTML string.
  82. * - lang: language key.
  83. * - image: image id in the storage and alignment (left, center, right) for example: 36\#center
  84. * - rss: URL to RSS with number of displayed items, for example: http://www.example.com/rss#4
  85. * - menu: menu object name.
  86. * - service: serialized array of service call parameters: module - module name, method - service method name, params - array of parameters.
  87. * - deletable: is block deletable from page builder
  88. * - copyable: is block can be copied to any other page from page builder.
  89. * - order: block order in particular cell.
  90. *
  91. * Block design boxes are stored in 'sys_pages_design_boxes' table:
  92. * - id: consistent id, there are the following defines can be used in the code for each system block style:
  93. * - 0 - BX_DB_CONTENT_ONLY: design box with content only - no borders, no background, no caption.
  94. * - 1 - BX_DB_DEF: default design box with content, borders and caption.
  95. * - 2 - BX_DB_EMPTY: just empty design box, without anything.
  96. * - 3 - BX_DB_NO_CAPTION: design box with content, like BX_DB_DEF but without caption.
  97. * - 10 - BX_DB_PADDING_CONTENT_ONLY: design box with content only wrapped with default padding - no borders, no background, no caption; it can be used to just wrap content with default padding.
  98. * - 11 - BX_DB_PADDING_DEF: default design box with content wrapped with default padding, borders and caption.
  99. * - 13 - BX_DB_PADDING_NO_CAPTION: design box with content wrapped with default padding, like BX_DB_DEF but without caption.
  100. * - title: block name which is displayed in studio, describes block styles.
  101. * - template: template name to use to display page block.
  102. *
  103. *
  104. * 3. Display Page.
  105. * Use the following sample code to display page:
  106. * @code
  107. * $oPage = BxDolPage::getObjectInstance('sample'); // 'sample' is 'object' field from 'sys_objects_page' table, it automatically creates instance of default or custom class by object name
  108. * if ($oPage)
  109. * echo $oPage->getCode(); // print page
  110. * @endcode
  111. *
  112. */
  113. class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolReplaceable
  114. {
  115. protected $_sObject;
  116. protected $_aObject;
  117. protected $_oQuery;
  118. protected $_aMarkers = array ();
  119. /**
  120. * Constructor
  121. * @param $aObject array of page options
  122. */
  123. protected function __construct($aObject)
  124. {
  125. parent::__construct();
  126. $this->_sObject = $aObject['object'];
  127. $this->_aObject = $aObject;
  128. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  129. }
  130. /**
  131. * Get page object instance by Module name and page URI
  132. * @param $sModule module name
  133. * @param $sURI unique page URI
  134. * @return object instance or false on error
  135. */
  136. static public function getObjectInstanceByModuleAndURI($sModule, $sURI = '', $oTemplate = false)
  137. {
  138. if(empty($sURI) && bx_get('i') !== false)
  139. $sURI = bx_process_input(bx_get('i'));
  140. if(empty($sURI))
  141. return false;
  142. $sObject = BxDolPageQuery::getPageObjectNameByURI($sURI, $sModule);
  143. return $sObject ? self::getObjectInstance($sObject, $oTemplate) : false;
  144. }
  145. /**
  146. * Get page object instance by page URI
  147. * @param $sURI unique page URI
  148. * @return object instance or false on error
  149. */
  150. static public function getObjectInstanceByURI($sURI = '', $oTemplate = false, $bRedirectCheck = false)
  151. {
  152. if(empty($sURI) && bx_get('i') !== false)
  153. $sURI = bx_process_input(bx_get('i'));
  154. if(empty($sURI))
  155. return false;
  156. $sObject = BxDolPageQuery::getPageObjectNameByURI($sURI);
  157. if ($bRedirectCheck && !$sObject && '/' == substr($sURI, -1)) {
  158. header("HTTP/1.1 301 Moved Permanently");
  159. unset($_GET['i']);
  160. header ('Location:' . bx_append_url_params(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . trim($sURI, '/')), $_GET));
  161. exit;
  162. }
  163. return $sObject ? self::getObjectInstance($sObject, $oTemplate) : false;
  164. }
  165. /**
  166. * Get page object instance by object name
  167. * @param $sObject object name
  168. * @return object instance or false on error
  169. */
  170. static public function getObjectInstance($sObject, $oTemplate = false)
  171. {
  172. if (isset($GLOBALS['bxDolClasses']['BxDolPage!'.$sObject]))
  173. return $GLOBALS['bxDolClasses']['BxDolPage!'.$sObject];
  174. $aObject = BxDolPageQuery::getPageObject($sObject);
  175. if (!$aObject || !is_array($aObject))
  176. return false;
  177. $sClass = 'BxTemplPage';
  178. if (!empty($aObject['override_class_name'])) {
  179. $sClass = $aObject['override_class_name'];
  180. if (!empty($aObject['override_class_file']))
  181. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  182. }
  183. $o = new $sClass($aObject, $oTemplate);
  184. return ($GLOBALS['bxDolClasses']['BxDolPage!'.$sObject] = $o);
  185. }
  186. /**
  187. * Process page triggers.
  188. * Page triggers allow to automatically add page blocks to modules with no different if dependant module was install before or after the module page block belongs to.
  189. * For example module "Notes" adds page blocks to all profiles modules (Persons, Organizations, etc)
  190. * with no difference if persons module was installed before or after "Notes" module was installed.
  191. * @param $sPageTriggerName trigger name to process, usually specified in module installer class - @see BxBaseModGeneralInstaller
  192. * @return always true, always success
  193. */
  194. static public function processPageTrigger ($sPageTriggerName)
  195. {
  196. // get list of active modules
  197. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array(
  198. 'type' => 'modules',
  199. 'active' => 1,
  200. ));
  201. // get list of page block triggers
  202. $aPageBlocks = BxDolPageQuery::getPageTriggers($sPageTriggerName);
  203. // check each page block trigger for all modules
  204. foreach ($aPageBlocks as $aPageBlock) {
  205. foreach ($aModules as $aModule) {
  206. if (!BxDolRequest::serviceExists($aModule['name'], 'get_page_object_for_page_trigger'))
  207. continue;
  208. $mixedPageObject = BxDolService::call($aModule['name'], 'get_page_object_for_page_trigger', array($sPageTriggerName));
  209. if (!$mixedPageObject)
  210. continue;
  211. $aPageBlockRow = $aPageBlock;
  212. if (is_array($mixedPageObject))
  213. $aPageBlockRow = array_merge($aPageBlockRow, $mixedPageObject);
  214. else
  215. $aPageBlockRow['object'] = $mixedPageObject;
  216. BxDolPageQuery::addPageBlockToPage($aPageBlockRow);
  217. }
  218. }
  219. return true;
  220. }
  221. /**
  222. * Delete SEO link
  223. * @param $sModule module name
  224. * @param $sContentInfoObject content info object
  225. * @param $sId content id
  226. * @return number of affected rows
  227. */
  228. static public function deleteSeoLink ($sModule, $sContentInfoObject, $sId)
  229. {
  230. return BxDolPageQuery::deleteSeoLink($sModule, $sContentInfoObject, $sId);
  231. }
  232. /**
  233. * Delete SEO links by param
  234. * @param $sParamName GET param name
  235. * @param $sId content id
  236. * @return number of affected rows
  237. */
  238. static public function deleteSeoLinkByParam ($sParamName, $sId)
  239. {
  240. return BxDolPageQuery::deleteSeoLinkByParam($sParamName, $sId);
  241. }
  242. /**
  243. * Delete SEO links by module
  244. * @param $sModule module name
  245. * @return number of affected rows
  246. */
  247. static public function deleteSeoLinkByModule ($sModule)
  248. {
  249. return BxDolPageQuery::deleteSeoLinkByModule($sModule);
  250. }
  251. /**
  252. * Process SEO links. It takes request part from SEO link and process it
  253. * to make it work as regular page link
  254. * @param $sRequest request URI with SEO link
  255. * @return true - if page was found and processed correctly, false - if page wasn't found
  256. */
  257. static public function processSeoLink ($sRequest)
  258. {
  259. if (!$sRequest || '/' === $sRequest || !getParam('permalinks_seo_links'))
  260. return false;
  261. // redirect to the correct URL
  262. if ('/' === $sRequest[-1] || $sRequest != mb_strtolower($sRequest)) {
  263. unset($_GET['_q']);
  264. $sUrl = BX_DOL_URL_ROOT . bx_append_url_params(mb_strtolower(trim($sRequest, '/')), $_GET);
  265. header('Location:' . $sUrl, true, 301);
  266. exit;
  267. }
  268. // parse URL
  269. $a = explode('/', $sRequest);
  270. if (!$a || empty($a[0]))
  271. return false;
  272. // check page URI rewrite redirect
  273. $aSeoUriRewrites = BxDolPageQuery::getSeoUriRewrites();
  274. if (isset($aSeoUriRewrites[$a[0]])) {
  275. unset($_GET['_q']);
  276. $a[0] = $aSeoUriRewrites[$a[0]];
  277. $sUrl = BX_DOL_URL_ROOT . bx_append_url_params(mb_strtolower(implode('/', $a)), $_GET);
  278. header('Location:' . $sUrl, true, 301);
  279. exit;
  280. }
  281. // check page URI rewrite
  282. $aSeoUriRewritesInv = array_flip($aSeoUriRewrites);
  283. if (isset($aSeoUriRewritesInv[$a[0]]))
  284. $a[0] = $aSeoUriRewritesInv[$a[0]];
  285. // get page
  286. $sPageName = BxDolPageQuery::getPageObjectNameByURI($a[0]);
  287. $aPage = $sPageName ? BxDolPageQuery::getPageObject($sPageName) : false;
  288. if (!$aPage)
  289. return false;
  290. // page with params
  291. if (!empty($a[1])) {
  292. $r = BxDolPageQuery::getSeoLink($aPage['module'], $a[0], ['uri' => $a[1]]);
  293. if ($r)
  294. $_GET[$r['param_name']] = $_REQUEST[$r['param_name']] = $r['param_value'];
  295. }
  296. // display page
  297. $_REQUEST['i'] = $_GET['i'] = $a[0];
  298. $oPage = BxDolPage::getObjectInstanceByURI($a[0], false, true);
  299. $oPage->displayPage();
  300. return true;
  301. }
  302. /**
  303. * Transform regular link to SEO link. It takes regular list as param and return SEO link.
  304. * @param $sLink regular link
  305. * @param $sPrefix prefix to add to the final URL, usually BX_DOL_URL_ROOT
  306. * @param $aParams additional GET params
  307. * @return SEO link string on success, false if transform failed or not necessary
  308. */
  309. static public function transformSeoLink ($sLink, $sPrefix, $aParams = array())
  310. {
  311. if (!getParam('permalinks_seo_links'))
  312. return false;
  313. if (0 !== strncmp('page.php', $sLink, 8)) // only page.php links are supported
  314. return false;
  315. $sQuery = parse_url($sLink, PHP_URL_QUERY);
  316. if (false === $sQuery)
  317. return false;
  318. if (function_exists('bx_parse_str'))
  319. $aQueryParams = bx_parse_str($sQuery);
  320. else
  321. parse_str($sQuery, $aQueryParams);
  322. $sPageUri = !empty($aQueryParams['i']) ? $aQueryParams['i'] : false;
  323. unset($aQueryParams['i']);
  324. if (!$sPageUri) // page URI wasn't found
  325. return false;
  326. $aSeoParams = array('id', 'profile_id'); // supported SEO params which are transformed to SEO strings
  327. $sSeoParamName = '';
  328. $sSeoParamValue = '';
  329. foreach ($aSeoParams as $k) {
  330. if (empty($aQueryParams[$k]) && empty($aParams[$k]))
  331. continue;
  332. $sSeoParamName = $k;
  333. $sSeoParamValue = !empty($aParams[$k]) ? $aParams[$k] : $aQueryParams[$k];
  334. unset($aQueryParams[$k]);
  335. unset($aParams[$k]);
  336. break; // only 1 SEO param will be transformed
  337. }
  338. if (!empty($sSeoParamValue) && 0 === strpos($sSeoParamValue, '{'))
  339. return false;
  340. $sSeoPageUri = $sPageUri;
  341. $aSeoUriRewrites = BxDolPageQuery::getSeoUriRewrites();
  342. if (isset($aSeoUriRewrites[$sSeoPageUri]))
  343. $sSeoPageUri = $aSeoUriRewrites[$sSeoPageUri];
  344. if ($sSeoParamName && $sSeoParamValue) { // process page with SEO param
  345. $sPageName = BxDolPageQuery::getPageObjectNameByURI($sPageUri);
  346. $aPage = $sPageName ? BxDolPageQuery::getPageObject($sPageName) : false;
  347. if ($aPage) {
  348. $sModule = $aPage['module'];
  349. $sContentInfo = !empty($aPage['content_info']) ? $aPage['content_info'] : $aPage['module'];
  350. if ('id' == $sSeoParamName) {
  351. $oContentInfo = BxDolContentInfo::getObjectInstance($sContentInfo);
  352. $sSeoTitle = $oContentInfo ? $oContentInfo->getContentTitle($sSeoParamValue) : '';
  353. if (!$sSeoTitle)
  354. $sSeoTitle = self::getSeoHash($sSeoParamValue);
  355. }
  356. elseif ('profile_id' == $sSeoParamName) {
  357. $oProfile = BxDolProfile::getInstance($sSeoParamValue);
  358. $sSeoTitle = $oProfile ? $oProfile->getDisplayName() : self::getSeoHash($sSeoParamValue);
  359. }
  360. $r = BxDolPageQuery::getSeoLink($sModule, $sPageUri, ['param_value' => $sSeoParamValue]);
  361. if (!$r) {
  362. $sSeoTitleLimited = BxTemplFunctions::getInstance()->getStringWithLimitedLength($sSeoTitle, 45);
  363. $sUri = uriGenerate ($sSeoTitleLimited, 'sys_seo_links', 'uri', '-', '-', ['module' => $sModule, 'page_uri' => $sPageUri]);
  364. bx_alert('system', 'uri-generate', 0, false, [
  365. 'module' => $sModule,
  366. 'page_uri' =>$sPageUri,
  367. 'param_name' => $sSeoParamName,
  368. 'param_value' => $sSeoParamValue,
  369. 'title' => $sSeoTitle,
  370. 'uri' => &$sUri,
  371. ]);
  372. BxDolPageQuery::insertSeoLink($sModule, $sPageUri, $sSeoParamName, $sSeoParamValue, $sUri);
  373. }
  374. elseif ($r['param_name'] == $sSeoParamName) {
  375. $sUri = $r['uri'];
  376. }
  377. else {
  378. $sUri = false;
  379. }
  380. if ($sUri)
  381. $sSeoPageUri .= '/' . $sUri;
  382. else
  383. $sSeoPageUri = false;
  384. }
  385. }
  386. if (!$sSeoPageUri)
  387. return false;
  388. return $sPrefix . bx_append_url_params($sSeoPageUri, array_merge($aQueryParams, $aParams), false);
  389. }
  390. /**
  391. * Transform SEO regular link into regular link with permalinks off.
  392. * @param $sSeoLink SEO link
  393. * @param $sPrefix prefix to add to the final URL, usually BX_DOL_URL_ROOT
  394. * @return unSEO link string on success, false if no transform is needed
  395. */
  396. static public function untransformSeoLink ($sSeoLink, $sPrefix)
  397. {
  398. // check for standard links first
  399. if (preg_match('/^(page\/|s\/|m\/|modules\/|page\.php|storage\.php)/', $sSeoLink))
  400. return false;
  401. // parse link
  402. $aParts = parse_url($sSeoLink);
  403. if (!$aParts || empty($aParts['path']))
  404. return false;
  405. $aUris = explode('/', trim($aParts['path'], '/'));
  406. // check if link starts with page URI and page with this URI exists
  407. if (!$aUris || empty($aUris[0]) || !($sPageName = BxDolPageQuery::getPageObjectNameByURI($aUris[0])))
  408. return false;
  409. // make final URL
  410. $s = 'page.php?i=' . $aUris[0];
  411. // add params
  412. if (!empty($aUris[1])) {
  413. $aPage = BxDolPageQuery::getPageObject($sPageName);
  414. if ($aPage) {
  415. $r = BxDolPageQuery::getSeoLink($aPage['module'], $aUris[0], ['uri' => urldecode($aUris[1])]);
  416. if (!$r)
  417. return false;
  418. $s .= '&' . $r['param_name'] . '=' . $r['param_value'];
  419. }
  420. }
  421. return $s . (!empty($aParts['query']) ? '&' . $aParts['query'] : '');
  422. }
  423. /**
  424. * Perform SEO redorect from regular pages if needed
  425. * @param $sSeoLink SEO link
  426. * @param $sPrefix prefix to add to the final URL, usually BX_DOL_URL_ROOT
  427. * @return unSEO link string on success, false if no transform is needed
  428. */
  429. static public function seoRedirect ()
  430. {
  431. if (!getParam('permalinks_seo_links'))
  432. return;
  433. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  434. $sLink = bx_append_url_params($sPageLink, $aPageParams);
  435. if (0 === strpos($sLink, BX_DOL_URL_ROOT))
  436. $sLink = substr($sLink, strlen(BX_DOL_URL_ROOT));
  437. if ($sSeoLink = self::transformSeoLink ($sLink, BX_DOL_URL_ROOT)) {
  438. header("Location:{$sSeoLink}", true, 301);
  439. exit;
  440. }
  441. }
  442. static public function getSeoHash($s)
  443. {
  444. return base_convert(substr(md5($s), -8), 16, 36);
  445. }
  446. /**
  447. * Static method to Get embed code
  448. * @return string.
  449. */
  450. static public function getEmbedData ($sUrl)
  451. {
  452. $sUrl = urldecode($sUrl);
  453. $aParams = [];
  454. $aUrl = bx_get_base_url($sUrl);
  455. if (!isset($aUrl[1]['i'])){
  456. return [];
  457. }
  458. $sUri = $aUrl[1]['i'];
  459. unset($aUrl[1]['i']);
  460. $aParams = $aUrl[1];
  461. $sAuthorName = $sAuthorUrl = $sThumb = '';
  462. if (isset($aParams['id'])){
  463. $sContentInfoObject = BxDolPageQuery::getContentInfoObjectNameByURI($sUri);
  464. $oContentInfo = BxDolContentInfo::getObjectInstance($sContentInfoObject);
  465. $sTitle = $oContentInfo->getContentTitle($aParams['id']);
  466. $iAuthor = $oContentInfo->getContentAuthor($aParams['id']);
  467. $sAuthorName = BxDolProfile::getInstance($iAuthor)->getDisplayName();
  468. $sAuthorUrl = BxDolProfile::getInstance($iAuthor)->getUrl();
  469. $sThumb = $oContentInfo->getContentThumb($aParams['id']);
  470. $sHtml = $oContentInfo->getContentEmbed($aParams['id']);
  471. }
  472. else{
  473. $oPage = BxDolPage::getObjectInstanceByURI($sUri, false, true);
  474. $aPage = $oPage->getObject();
  475. $sTitle = $oPage->_getPageTitle();
  476. $sHtml = BxDolTemplate::getInstance()->parseHtmlByName('embed.html', [
  477. 'title' => $sTitle,
  478. 'url' => BX_DOL_URL_ROOT . 'page.php?a=embed&o=' . $oPage->getName()
  479. ]);
  480. }
  481. return ['url' => $sUrl, 'title' => $sTitle, 'author_name' => $sAuthorName, 'author_url' => $sAuthorUrl, 'thumbnail_url' => $sThumb, 'html' => $sHtml];
  482. }
  483. /**
  484. * Display complete page
  485. */
  486. public function displayPage ($oTemplate = null)
  487. {
  488. if (!$oTemplate)
  489. $oTemplate = BxDolTemplate::getInstance();
  490. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  491. $oTemplate->setPageUrl($this->_aObject['url']);
  492. $oTemplate->setPageType ($this->getType());
  493. $oTemplate->setPageInjections ($this->getInjections());
  494. $oTemplate->setPageContent ('page_main_code', $this->getCode());
  495. $oTemplate->getPageCode();
  496. }
  497. public function getId ()
  498. {
  499. return (int)$this->_aObject['id'];
  500. }
  501. public function getType ()
  502. {
  503. return (int)$this->_aObject['type_id'];
  504. }
  505. public function getModule ()
  506. {
  507. return $this->_aObject['module'];
  508. }
  509. public function getSubMenu ()
  510. {
  511. return $this->_aObject['submenu'];
  512. }
  513. public function getName ()
  514. {
  515. return $this->_sObject;
  516. }
  517. public function getObject ()
  518. {
  519. return $this->_aObject;
  520. }
  521. public function getInjections()
  522. {
  523. $aResult = array();
  524. foreach($this->_aObject as $sKey => $sValue)
  525. if(strpos($sKey, 'inj_') === 0)
  526. $aResult[substr($sKey, 4)] = $sValue;
  527. return $aResult;
  528. }
  529. /**
  530. * Add replace markers. Markers are replaced in raw, html, lang blocks and page title, description, keywords and block titles.
  531. * @param $a array of markers as key => value
  532. * @return true on success or false on error
  533. */
  534. public function addMarkers ($a)
  535. {
  536. if (empty($a) || !is_array($a))
  537. return false;
  538. $this->_aMarkers = array_merge ($this->_aMarkers, $a);
  539. return true;
  540. }
  541. public function isVisiblePage ()
  542. {
  543. return $this->_isVisiblePage($this->_aObject);
  544. }
  545. public function isVisiblePageSubmenu ()
  546. {
  547. return $this->_aObject['submenu'] != 'disabled';
  548. }
  549. public function isEditAllowed ()
  550. {
  551. return false;
  552. }
  553. public function isDeleteAllowed ()
  554. {
  555. return false;
  556. }
  557. /**
  558. * Replace provided markers in a string
  559. * @param $mixed string or array to replace markers in
  560. * @return string where all occured markers are replaced
  561. */
  562. protected function _replaceMarkers ($mixed, $aAdditionalMarkers = array())
  563. {
  564. return bx_replace_markers($mixed, array_merge($this->_aMarkers, $aAdditionalMarkers));
  565. }
  566. /**
  567. * Check if page block is visible.
  568. */
  569. protected function _isVisibleBlock ($a)
  570. {
  571. return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
  572. }
  573. /**
  574. * Check if page is visible.
  575. */
  576. protected function _isVisiblePage ($a, $bRedirectToLoginFormForUnauthenticated = false)
  577. {
  578. if (!isLogged() && getParam('sys_lock_from_unauthenticated') && !defined('BX_DOL_CRON_EXECUTE')) {
  579. $aURIs = explode(',', getParam('sys_lock_from_unauthenticated_exceptions'));
  580. array_walk($aURIs, function (&$sVal) {
  581. $sVal = trim($sVal);
  582. });
  583. $aI = array_combine($aURIs, array_fill(0, count($aURIs), 1));
  584. if (!preg_match('/\/oauth2\//', $_SERVER['REQUEST_URI']) /*&& !preg_match('/searchKeyword.php$/', $_SERVER['PHP_SELF'])*/ && !preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$this->_aObject['uri']])) {
  585. if ($bRedirectToLoginFormForUnauthenticated) {
  586. $this->_redirectToLoginForm();
  587. }
  588. else {
  589. return false;
  590. }
  591. }
  592. }
  593. return isAdmin() || BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
  594. }
  595. protected function _redirectToLoginForm ()
  596. {
  597. header("Location: " . bx_append_url_params(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=login'), ['relocate' => bx_get_self_url()]));
  598. exit;
  599. }
  600. }
  601. /** @} */