BxDolStudioPage.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 UnaStudio UNA Studio
  7. * @{
  8. */
  9. define('BX_DOL_STUDIO_PAGE_HOME', 'home');
  10. define('BX_DOL_STUDIO_PAGE_JS_OBJECT', 'oBxDolStudioPage');
  11. define('BX_DOL_STUDIO_MIT_CAPTION', 'caption');
  12. define('BX_DOL_STUDIO_MIT_ITEM', 'item');
  13. class BxDolStudioPage extends BxDol
  14. {
  15. protected $oDb;
  16. protected $aPage;
  17. protected $bPage;
  18. protected $bPageMultiple;
  19. protected $sPageUrl;
  20. protected $sPageSelected;
  21. protected $sPageRssHelpObject;
  22. protected $sPageRssHelpUrl;
  23. protected $iPageRssHelpLength;
  24. protected $sPageRssHelpId;
  25. protected $_sTypesPreList;
  26. protected $aActions;
  27. protected $aMarkers;
  28. protected $iError;
  29. protected $sError;
  30. protected $_bShowHeaderBreadcrumb;
  31. protected $_bShowHeaderRightSearch;
  32. protected $_bShowHeaderRightSite;
  33. protected $_bShowHeaderRightAssistant;
  34. function __construct($mixedPageName)
  35. {
  36. parent::__construct();
  37. $this->oDb = BxDolStudioPageQuery::getInstance();
  38. $this->aPage = [];
  39. $this->bPage = false;
  40. $this->bPageMultiple = false;
  41. $this->sPageSelected = '';
  42. $this->sPageRssHelpObject = 'sys_studio_page_help';
  43. $this->sPageRssHelpUrl = 'http://feed.una.io/?section={page_name}';
  44. $this->iPageRssHelpLength = 5;
  45. $this->_sTypesPreList = 'sys_studio_widget_types';
  46. $this->aActions = [];
  47. $this->aMarkers = [
  48. 'url_root' => BX_DOL_URL_ROOT,
  49. 'url_studio' => BX_DOL_URL_STUDIO
  50. ];
  51. $this->iError = 0;
  52. $this->sError = false;
  53. $this->_bShowHeaderBreadcrumb = getParam('sys_std_show_header_left') == 'on';
  54. $this->_bShowHeaderRightSearch = getParam('sys_std_show_header_right_search') == 'on';
  55. $this->_bShowHeaderRightSite = getParam('sys_std_show_header_right_site') == 'on';
  56. $this->_bShowHeaderRightAssistant = false;
  57. if(is_string($mixedPageName)) {
  58. $this->aPage = $this->oDb->getPages(array('type' => 'by_page_name_full', 'value' => $mixedPageName));
  59. if(empty($this->aPage) || !is_array($this->aPage))
  60. return;
  61. }
  62. else if(is_array($mixedPageName)) {
  63. $aPages = $this->oDb->getPages(array('type' => 'by_page_names_full', 'value' => array_keys($mixedPageName)));
  64. if(empty($aPages) || !is_array($aPages))
  65. return;
  66. $this->bPageMultiple = true;
  67. foreach($aPages as $aPage) {
  68. if((int)$mixedPageName[$aPage['name']] == 1)
  69. $this->sPageSelected = $aPage['name'];
  70. $this->aPage[$aPage['name']] = $aPage;
  71. }
  72. }
  73. $this->bPage = true;
  74. }
  75. public function checkAction()
  76. {
  77. return false;
  78. }
  79. public function getDb()
  80. {
  81. return $this->oDb;
  82. }
  83. public function getPageUrl()
  84. {
  85. if(empty($this->sPageUrl) && !empty($this->aPage['wid_url']))
  86. $this->sPageUrl = $this->aPage['wid_url'];
  87. return bx_replace_markers($this->sPageUrl, $this->aMarkers);
  88. }
  89. public function getPageTypeUrl()
  90. {
  91. $sUrl = BxTemplStudioLauncher::getInstance()->getPageUrl();
  92. if(empty($this->aPage['wid_type']))
  93. return $sUrl;
  94. return bx_append_url_params($sUrl, array(
  95. 'type' => $this->aPage['wid_type']
  96. ));
  97. }
  98. public function getRssHelpUrl()
  99. {
  100. return bx_replace_markers($this->sPageRssHelpUrl, $this->aMarkers);
  101. }
  102. public function getPageTypes($bFullInfo = true)
  103. {
  104. return BxDolFormQuery::getDataItems($this->_sTypesPreList, false, $bFullInfo ? BX_DATA_VALUES_ALL : BX_DATA_VALUES_DEFAULT);
  105. }
  106. public function getPageTypeIcon()
  107. {
  108. if(empty($this->aPage['wid_type']))
  109. return false;
  110. $sType = $this->aPage['wid_type'];
  111. $aTypes = $this->getPageTypes();
  112. if(empty($aTypes[$sType]) || empty($aTypes[$sType]['Data']))
  113. return false;
  114. $aTypeData = unserialize($aTypes[$sType]['Data']);
  115. if(empty($aTypeData['icon']))
  116. return false;
  117. return $aTypeData['icon'];
  118. }
  119. /**
  120. * Add replace markers.
  121. * @param $a array of markers as key => value
  122. * @return true on success or false on error
  123. */
  124. public function addMarkers ($a)
  125. {
  126. if(empty($a) || !is_array($a))
  127. return false;
  128. $this->aMarkers = array_merge($this->aMarkers, $a);
  129. return true;
  130. }
  131. public function setError($mixedError)
  132. {
  133. if(is_array($mixedError))
  134. list($this->iError, $this->sError) = $mixedError;
  135. else
  136. $this->sError = $mixedError;
  137. }
  138. public function getError($bToDisplay = true)
  139. {
  140. $sError = $this->sError;
  141. if($bToDisplay)
  142. $sError = MsgBox(_t($sError));
  143. return $this->iError ? [$this->iError, $sError]: $sError;
  144. }
  145. protected function getSystemName($sValue)
  146. {
  147. return BxDolStudioUtils::getSystemName($sValue);
  148. }
  149. protected function getClassName($sValue)
  150. {
  151. return BxDolStudioUtils::getClassName($sValue);
  152. }
  153. protected function getModuleTitle($sName)
  154. {
  155. return BxDolStudioUtils::getModuleTitle($sName);
  156. }
  157. protected function getModuleIcon($sName, $sType = 'menu', $bReturnAsUrl = true)
  158. {
  159. return BxDolStudioUtils::getModuleIcon($sName, $sType, $bReturnAsUrl);
  160. }
  161. protected function getModules($bShowCustom = true, $bShowSystem = true)
  162. {
  163. return BxDolStudioUtils::getModules($bShowCustom, $bShowSystem);
  164. }
  165. protected function updateHistory()
  166. {
  167. if(empty($this->aPage['wid_id']))
  168. return;
  169. BxTemplStudioMenuTop::historyAdd($this->aPage);
  170. }
  171. }
  172. /** @} */