BxDolStudioPage.php 6.2 KB

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