BxDolStudioPage.php 5.5 KB

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