BxDolStudioPage.php 6.0 KB

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