BxDolPage.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolPageQuery');
  10. /**
  11. * @page objects
  12. * @section page Page
  13. * @ref BxDolPage
  14. */
  15. /**
  16. * Pages.
  17. *
  18. * It allows to display pages which are built from studio.
  19. *
  20. * The new system has the following page features:
  21. * - Layouts: page can have any structure, not just columns.
  22. * - SEO: page can have own SEO options, like meta tags and meta keywords, as well as instructions for search bots.
  23. * - Cache: page can be cached on the server.
  24. * - Access control: page access can be controlled using member levels.
  25. *
  26. *
  27. *
  28. * @section page_create Creating the Page object:
  29. *
  30. * 1. add record to 'sys_objects_page' table:
  31. *
  32. * - 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.
  33. * - title: name to display as page title.
  34. * - module: the module this page belongs to.
  35. * - layout_id: page layout to use, this is id of the record from 'sys_pages_layouts' table.
  36. * - 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:
  37. * - user level id = 1 -> 2^(1-1) = 1
  38. * - user level id = 2 -> 2^(2-1) = 2
  39. * - user level id = 3 -> 2^(3-1) = 4
  40. * - user level id = 4 -> 2^(4-1) = 8
  41. * - 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.
  42. * - url: the page url, if it is static page.
  43. * - meta_description: meta description of the page.
  44. * - meta_keywords: meta keywords of the page.
  45. * - meta_robots: instructions for search bots.
  46. * - cache_lifetime: number of seconds to store cache for.
  47. * - cache_editable: it determines if cache can be edited from page builder.
  48. * - deletable: it determines if page can be deleted from page builder.
  49. * - override_class_name: user defined class name which is derived from BxTemplPage.
  50. * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
  51. *
  52. * 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.
  53. *
  54. *
  55. * Page layout are stored in 'sys_pages_layouts' table:
  56. * - name: inner unique layout name.
  57. * - icon: layout icon to display in page builder, it should represent basic view of the layout to help studio operator determine the layout structure.
  58. * - title: layout name to display in page builder.
  59. * - template: template name to use to display page with certain layout.
  60. * - cells_number: number of areas in the layout, page blocks can be places into this areas(cells).
  61. * To define areas in the layout they should be named as '__cell_N__', where N is cell number, starting from 1.
  62. *
  63. *
  64. * 2. Add page blocks to 'sys_pages_blocks' table:
  65. * - object: page object name this block belongs to.
  66. * - cell_id: cell number in page layout to place block to.
  67. * - module: module name this block belongs to.
  68. * - title: block title.
  69. * - designbox_id: design box to use to diplay page block, it is id of the record from 'sys_pages_design_boxes' table.
  70. * - 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:
  71. * - user level id = 1 -> 2^(1-1) = 1
  72. * - user level id = 2 -> 2^(2-1) = 2
  73. * - user level id = 3 -> 2^(3-1) = 4
  74. * - user level id = 4 -> 2^(4-1) = 8
  75. * - type: block type
  76. * - raw: HTML block, displayed in page builder as HTML textarea.
  77. * - html: HTML block, displayed in page builder as visual editor, like TinyMCE.
  78. * - lang: translatable language string, displayed in page builder as editable language key.
  79. * - image: just an image, displayed in page builder as HTML upload form.
  80. * - rss: RSS block, displayed in page builder as editable URL to RSS resource, along with number of displayed items.
  81. * - menu: menu block, displayed as menu selector.
  82. * - service: to display block content, the provided service method is used.
  83. * - content: depending on 'type' field:
  84. * - raw: HTML string.
  85. * - html: HTML string.
  86. * - lang: language key.
  87. * - image: image id in the storage and alignment (left, center, right) for example: 36#center
  88. * - rss: URL to RSS with number of displayed items, for example: http://www.example.com/rss#4
  89. * - menu: menu object name.
  90. * - service: serialized array of service call parameters: module - module name, method - service method name, params - array of parameters.
  91. * - deletable: is block deletable from page builder
  92. * - copyable: is block can be copied to any other page from page builder.
  93. * - order: block order in particular cell.
  94. *
  95. * Block design boxes are stored in 'sys_pages_design_boxes' table:
  96. * - id: consistent id, there are the following defines can be used in the code for each system block style:
  97. * - 0 - BX_DB_CONTENT_ONLY: design box with content only - no borders, no background, no caption.
  98. * - 1 - BX_DB_DEF: default design box with content, borders and caption.
  99. * - 2 - BX_DB_EMPTY: just empty design box, without anything.
  100. * - 3 - BX_DB_NO_CAPTION: design box with content, like BX_DB_DEF but without caption.
  101. * - 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.
  102. * - 11 - BX_DB_PADDING_DEF: default design box with content wrapped with default padding, borders and caption.
  103. * - 13 - BX_DB_PADDING_NO_CAPTION: design box with content wrapped with default padding, like BX_DB_DEF but without caption.
  104. * - title: block name which is displayed in studio, describes block styles.
  105. * - template: template name to use to display page block.
  106. *
  107. *
  108. * 3. Display Page.
  109. * Use the following sample code to display page:
  110. * @code
  111. * bx_import('BxDolPage');
  112. * $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
  113. * if ($oPage)
  114. * echo $oPage->getCode(); // print page
  115. * @endcode
  116. *
  117. */
  118. class BxDolPage extends BxDol implements iBxDolFactoryObject, iBxDolReplaceable {
  119. protected $_sObject;
  120. protected $_aObject;
  121. protected $_oQuery;
  122. protected $_aMarkers = array ();
  123. /**
  124. * Constructor
  125. * @param $aObject array of page options
  126. */
  127. public function __construct($aObject) {
  128. parent::__construct();
  129. $this->_sObject = $aObject['object'];
  130. $this->_aObject = $aObject;
  131. $this->_oQuery = new BxDolPageQuery($this->_aObject);
  132. }
  133. /**
  134. * Get page object instance by page URI
  135. * @param $sURI unique page URI
  136. * @return object instance or false on error
  137. */
  138. static public function getObjectInstanceByURI($sURI) {
  139. $sObject = BxDolPageQuery::getPageObjectNameByURI($sURI);
  140. return $sObject ? self::getObjectInstance($sObject) : false;
  141. }
  142. /**
  143. * Get page object instance by object name
  144. * @param $sObject object name
  145. * @return object instance or false on error
  146. */
  147. static public function getObjectInstance($sObject) {
  148. if (isset($GLOBALS['bxDolClasses']['BxDolPage!'.$sObject]))
  149. return $GLOBALS['bxDolClasses']['BxDolPage!'.$sObject];
  150. $aObject = BxDolPageQuery::getPageObject($sObject);
  151. if (!$aObject || !is_array($aObject))
  152. return false;
  153. bx_import('BxTemplPage');
  154. $sClass = 'BxTemplPage';
  155. if (!empty($aObject['override_class_name'])) {
  156. $sClass = $aObject['override_class_name'];
  157. if (!empty($aObject['override_class_file']))
  158. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  159. else
  160. bx_import($sClass);
  161. }
  162. $o = new $sClass($aObject);
  163. return ($GLOBALS['bxDolClasses']['BxDolPage!'.$sObject] = $o);
  164. }
  165. /**
  166. * Add replace markers. Markers are replaced in raw, html, lang blocks and page title, description, keywords and block titles.
  167. * @param $a array of markers as key => value
  168. * @return true on success or false on error
  169. */
  170. public function addMarkers ($a) {
  171. if (empty($a) || !is_array($a))
  172. return false;
  173. $this->_aMarkers = array_merge ($this->_aMarkers, $a);
  174. return true;
  175. }
  176. /**
  177. * Replace provided markers in a string
  178. * @param $mixed string or array to replace markers in
  179. * @return string where all occured markers are replaced
  180. */
  181. protected function _replaceMarkers ($mixed) {
  182. return bx_replace_markers($mixed, $this->_aMarkers);
  183. }
  184. /**
  185. * Check if page block is visible.
  186. */
  187. protected function _isVisibleBlock ($a) {
  188. bx_import('BxDolAcl');
  189. return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
  190. }
  191. /**
  192. * Check if page is visible.
  193. */
  194. protected function _isVisiblePage ($a) {
  195. bx_import('BxDolAcl');
  196. return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
  197. }
  198. }
  199. /** @} */