BxDolStudioPage.php 5.2 KB

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