BxDolPage.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  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. // get page
  273. $sPageName = BxDolPageQuery::getPageObjectNameByURI($a[0]);
  274. $aPage = $sPageName ? BxDolPageQuery::getPageObject($sPageName) : false;
  275. if (!$aPage)
  276. return false;
  277. // page with params
  278. if (!empty($a[1])) {
  279. $r = BxDolPageQuery::getSeoLink($aPage['module'], $a[0], ['uri' => $a[1]]);
  280. if ($r)
  281. $_GET[$r['param_name']] = $_REQUEST[$r['param_name']] = $r['param_value'];
  282. }
  283. // display page
  284. $_REQUEST['i'] = $_GET['i'] = $a[0];
  285. $oPage = BxDolPage::getObjectInstanceByURI($a[0], false, true);
  286. $oPage->displayPage();
  287. return true;
  288. }
  289. /**
  290. * Transform regular link to SEO link. It takes regular list as param and return SEO link.
  291. * @param $sLink regular link
  292. * @param $sPrefix prefix to add to the final URL, usually BX_DOL_URL_ROOT
  293. * @param $aParams additional GET params
  294. * @return SEO link string on success, false if transform failed or not necessary
  295. */
  296. static public function transformSeoLink ($sLink, $sPrefix, $aParams = array())
  297. {
  298. if (!getParam('permalinks_seo_links'))
  299. return false;
  300. if (0 !== strncmp('page.php', $sLink, 8)) // only page.php links are supported
  301. return false;
  302. $sQuery = parse_url($sLink, PHP_URL_QUERY);
  303. if (false === $sQuery)
  304. return false;
  305. parse_str($sQuery, $aQueryParams);
  306. $sPageUri = !empty($aQueryParams['i']) ? $aQueryParams['i'] : false;
  307. unset($aQueryParams['i']);
  308. if (!$sPageUri) // page URI wasn't found
  309. return false;
  310. $aSeoParams = array('id', 'profile_id'); // supported SEO params which are transformed to SEO strings
  311. $sSeoParamName = '';
  312. $sSeoParamValue = '';
  313. foreach ($aSeoParams as $k) {
  314. if (empty($aQueryParams[$k]) && empty($aParams[$k]))
  315. continue;
  316. $sSeoParamName = $k;
  317. $sSeoParamValue = !empty($aParams[$k]) ? $aParams[$k] : $aQueryParams[$k];
  318. unset($aQueryParams[$k]);
  319. unset($aParams[$k]);
  320. break; // only 1 SEO param will be transformed
  321. }
  322. if (!empty($sSeoParamValue) && 0 === strpos($sSeoParamValue, '{'))
  323. return false;
  324. $sSeoPageUri = $sPageUri;
  325. if ($sSeoParamName && $sSeoParamValue) { // process page with SEO param
  326. $sPageName = BxDolPageQuery::getPageObjectNameByURI($sPageUri);
  327. $aPage = $sPageName ? BxDolPageQuery::getPageObject($sPageName) : false;
  328. if ($aPage) {
  329. $sModule = $aPage['module'];
  330. $sContentInfo = !empty($aPage['content_info']) ? $aPage['content_info'] : $aPage['module'];
  331. if ('id' == $sSeoParamName) {
  332. $oContentInfo = BxDolContentInfo::getObjectInstance($sContentInfo);
  333. $sSeoTitle = $oContentInfo ? $oContentInfo->getContentTitle($sSeoParamValue) : '';
  334. if (!$sSeoTitle)
  335. $sSeoTitle = self::getSeoHash($sSeoParamValue);
  336. }
  337. elseif ('profile_id' == $sSeoParamName) {
  338. $oProfile = BxDolProfile::getInstance($sSeoParamValue);
  339. $sSeoTitle = $oProfile ? $oProfile->getDisplayName() : self::getSeoHash($sSeoParamValue);
  340. }
  341. $r = BxDolPageQuery::getSeoLink($sModule, $sPageUri, ['param_value' => $sSeoParamValue]);
  342. if (!$r) {
  343. $sSeoTitleLimited = BxTemplFunctions::getInstance()->getStringWithLimitedLength($sSeoTitle, 45);
  344. $sUri = uriGenerate ($sSeoTitleLimited, 'sys_seo_links', 'uri', '-', '-', ['module' => $sModule, 'page_uri' => $sPageUri]);
  345. bx_alert('system', 'uri-generate', 0, false, [
  346. 'module' => $sModule,
  347. 'page_uri' =>$sPageUri,
  348. 'param_name' => $sSeoParamName,
  349. 'param_value' => $sSeoParamValue,
  350. 'title' => $sSeoTitle,
  351. 'uri' => &$sUri,
  352. ]);
  353. BxDolPageQuery::insertSeoLink($sModule, $sPageUri, $sSeoParamName, $sSeoParamValue, $sUri);
  354. }
  355. elseif ($r['param_name'] == $sSeoParamName) {
  356. $sUri = $r['uri'];
  357. }
  358. else {
  359. $sUri = false;
  360. }
  361. if ($sUri)
  362. $sSeoPageUri .= '/' . $sUri;
  363. else
  364. $sSeoPageUri = false;
  365. }
  366. }
  367. if (!$sSeoPageUri)
  368. return false;
  369. return $sPrefix . bx_append_url_params($sSeoPageUri, array_merge($aQueryParams, $aParams));
  370. }
  371. /**
  372. * Transform SEO regular link into regular link with permalinks off.
  373. * @param $sSeoLink SEO link
  374. * @param $sPrefix prefix to add to the final URL, usually BX_DOL_URL_ROOT
  375. * @return unSEO link string on success, false if no transform is needed
  376. */
  377. static public function untransformSeoLink ($sSeoLink, $sPrefix)
  378. {
  379. // check for standard links first
  380. if (preg_match('/^(page\/|s\/|m\/|modules\/|page\.php|storage\.php)/', $sSeoLink))
  381. return false;
  382. // parse link
  383. $aParts = parse_url($sSeoLink);
  384. if (!$aParts || empty($aParts['path']))
  385. return false;
  386. $aUris = explode('/', trim($aParts['path'], '/'));
  387. // check if link starts with page URI and page with this URI exists
  388. if (!$aUris || empty($aUris[0]) || !($sPageName = BxDolPageQuery::getPageObjectNameByURI($aUris[0])))
  389. return false;
  390. // make final URL
  391. $s = 'page.php?i=' . $aUris[0];
  392. // add params
  393. if (!empty($aUris[1])) {
  394. $aPage = BxDolPageQuery::getPageObject($sPageName);
  395. if ($aPage) {
  396. $r = BxDolPageQuery::getSeoLink($aPage['module'], $aUris[0], ['uri' => urldecode($aUris[1])]);
  397. if (!$r)
  398. return false;
  399. $s .= '&' . $r['param_name'] . '=' . $r['param_value'];
  400. }
  401. }
  402. return $s . (!empty($aParts['query']) ? '&' . $aParts['query'] : '');
  403. }
  404. /**
  405. * Perform SEO redorect from regular pages if needed
  406. * @param $sSeoLink SEO link
  407. * @param $sPrefix prefix to add to the final URL, usually BX_DOL_URL_ROOT
  408. * @return unSEO link string on success, false if no transform is needed
  409. */
  410. static public function seoRedirect ()
  411. {
  412. if (!getParam('permalinks_seo_links'))
  413. return;
  414. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  415. $sLink = bx_append_url_params($sPageLink, $aPageParams);
  416. if (0 === strpos($sLink, BX_DOL_URL_ROOT))
  417. $sLink = substr($sLink, strlen(BX_DOL_URL_ROOT));
  418. if ($sSeoLink = self::transformSeoLink ($sLink, BX_DOL_URL_ROOT)) {
  419. header("Location:{$sSeoLink}", true, 301);
  420. exit;
  421. }
  422. }
  423. static public function getSeoHash($s)
  424. {
  425. return base_convert(substr(md5($s), -8), 16, 36);
  426. }
  427. /**
  428. * Static method to Get embed code
  429. * @return string.
  430. */
  431. static public function getEmbedData ($sUrl)
  432. {
  433. $sUrl = urldecode($sUrl);
  434. $aParams = [];
  435. $aUrl = bx_get_base_url($sUrl);
  436. if (!isset($aUrl[1]['i'])){
  437. return [];
  438. }
  439. $sUri = $aUrl[1]['i'];
  440. unset($aUrl[1]['i']);
  441. $aParams = $aUrl[1];
  442. $sAuthorName = $sAuthorUrl = $sThumb = '';
  443. if (isset($aParams['id'])){
  444. $sContentInfoObject = BxDolPageQuery::getContentInfoObjectNameByURI($sUri);
  445. $oContentInfo = BxDolContentInfo::getObjectInstance($sContentInfoObject);
  446. $sTitle = $oContentInfo->getContentTitle($aParams['id']);
  447. $iAuthor = $oContentInfo->getContentAuthor($aParams['id']);
  448. $sAuthorName = BxDolProfile::getInstance()->getDisplayName($iAuthor);
  449. $sAuthorUrl = BxDolProfile::getInstance()->getUrl($iAuthor);
  450. $sThumb = $oContentInfo->getContentThumb($aParams['id']);
  451. $sHtml = $oContentInfo->getContentEmbed($aParams['id']);
  452. }
  453. else{
  454. $oPage = BxDolPage::getObjectInstanceByURI($sUri, false, true);
  455. $aPage = $oPage->getObject();
  456. $sTitle = $oPage->_getPageTitle();
  457. $sHtml = BxDolTemplate::getInstance()->parseHtmlByName('embed.html', [
  458. 'title' => $sTitle,
  459. 'url' => BX_DOL_URL_ROOT . 'page.php?a=embed&o=' . $oPage->getName()
  460. ]);
  461. }
  462. return ['url' => $sUrl, 'title' => $sTitle, 'author_name' => $sAuthorName, 'author_url' => $sAuthorUrl, 'thumbnail_url' => $sThumb, 'html' => $sHtml];
  463. }
  464. /**
  465. * Display complete page
  466. */
  467. public function displayPage ($oTemplate = null)
  468. {
  469. if (!$oTemplate)
  470. $oTemplate = BxDolTemplate::getInstance();
  471. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  472. $oTemplate->setPageType ($this->getType());
  473. $oTemplate->setPageInjections ($this->getInjections());
  474. $oTemplate->setPageContent ('page_main_code', $this->getCode());
  475. $oTemplate->getPageCode();
  476. }
  477. public function getId ()
  478. {
  479. return (int)$this->_aObject['id'];
  480. }
  481. public function getType ()
  482. {
  483. return (int)$this->_aObject['type_id'];
  484. }
  485. public function getModule ()
  486. {
  487. return $this->_aObject['module'];
  488. }
  489. public function getSubMenu ()
  490. {
  491. return $this->_aObject['submenu'];
  492. }
  493. public function getName ()
  494. {
  495. return $this->_sObject;
  496. }
  497. public function getObject ()
  498. {
  499. return $this->_aObject;
  500. }
  501. public function getInjections()
  502. {
  503. $aResult = array();
  504. foreach($this->_aObject as $sKey => $sValue)
  505. if(strpos($sKey, 'inj_') === 0)
  506. $aResult[substr($sKey, 4)] = $sValue;
  507. return $aResult;
  508. }
  509. /**
  510. * Add replace markers. Markers are replaced in raw, html, lang blocks and page title, description, keywords and block titles.
  511. * @param $a array of markers as key => value
  512. * @return true on success or false on error
  513. */
  514. public function addMarkers ($a)
  515. {
  516. if (empty($a) || !is_array($a))
  517. return false;
  518. $this->_aMarkers = array_merge ($this->_aMarkers, $a);
  519. return true;
  520. }
  521. public function isVisiblePage ()
  522. {
  523. return $this->_isVisiblePage($this->_aObject);
  524. }
  525. public function isEditAllowed ()
  526. {
  527. return false;
  528. }
  529. public function isDeleteAllowed ()
  530. {
  531. return false;
  532. }
  533. /**
  534. * Replace provided markers in a string
  535. * @param $mixed string or array to replace markers in
  536. * @return string where all occured markers are replaced
  537. */
  538. protected function _replaceMarkers ($mixed, $aAdditionalMarkers = array())
  539. {
  540. return bx_replace_markers($mixed, array_merge($this->_aMarkers, $aAdditionalMarkers));
  541. }
  542. /**
  543. * Check if page block is visible.
  544. */
  545. protected function _isVisibleBlock ($a)
  546. {
  547. return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
  548. }
  549. /**
  550. * Check if page is visible.
  551. */
  552. protected function _isVisiblePage ($a)
  553. {
  554. return isAdmin() || BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
  555. }
  556. }
  557. /** @} */