BxDolStudioPage.php 4.9 KB

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