BxDolStudioPage.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 $sPageSelected;
  19. protected $sPageRssHelpObject;
  20. protected $sPageRssHelpUrl;
  21. protected $iPageRssHelpLength;
  22. protected $sPageRssHelpId;
  23. protected $aActions;
  24. protected $aMarkers;
  25. function __construct($mixedPageName)
  26. {
  27. parent::__construct();
  28. $this->oDb = new BxDolStudioPageQuery();
  29. $this->aPage = array();
  30. $this->bPageMultiple = false;
  31. $this->sPageSelected = '';
  32. $this->sPageRssHelpObject = 'sys_studio_page_help';
  33. $this->sPageRssHelpUrl = 'http://feed.una.io/?section={page_name}';
  34. $this->iPageRssHelpLength = 5;
  35. $this->aActions = array();
  36. $this->aMarkers = array();
  37. if(is_string($mixedPageName)) {
  38. $this->oDb->getPages(array('type' => 'by_page_name_full', 'value' => $mixedPageName), $this->aPage, false);
  39. if(empty($this->aPage) || !is_array($this->aPage))
  40. return;
  41. $this->aPage['bookmarked'] = $this->oDb->isBookmarked($this->aPage);
  42. }
  43. else if(is_array($mixedPageName)) {
  44. $aPages = array();
  45. $this->oDb->getPages(array('type' => 'by_page_names_full', 'value' => array_keys($mixedPageName)), $aPages, false);
  46. if(empty($aPages) || !is_array($aPages))
  47. return;
  48. $this->bPageMultiple = true;
  49. foreach($aPages as $aPage) {
  50. if((int)$mixedPageName[$aPage['name']] == 1)
  51. $this->sPageSelected = $aPage['name'];
  52. $aPage['bookmarked'] = $this->oDb->isBookmarked($aPage);
  53. $this->aPage[$aPage['name']] = $aPage;
  54. }
  55. }
  56. if(!$this->bPageMultiple) {
  57. $this->sPageRssHelpId = $this->aPage['name'];
  58. $this->addAction(array(
  59. 'type' => 'switcher',
  60. 'name' => 'bookmark',
  61. 'caption' => '_adm_txt_pca_favorite',
  62. 'checked' => $this->aPage['bookmarked'],
  63. 'onchange' => "javascript:" . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".bookmark('" . $this->aPage['name'] . "', this)"
  64. ));
  65. $this->aMarkers['page_name'] = $this->aPage['name'];
  66. }
  67. }
  68. public function getRssHelpUrl()
  69. {
  70. return bx_replace_markers($this->sPageRssHelpUrl, $this->aMarkers);
  71. }
  72. public function addAction($aAction, $bOnRight = true)
  73. {
  74. if($bOnRight)
  75. $this->aActions[] = $aAction;
  76. else
  77. $this->aActions = array_merge(array($aAction), $this->aActions);
  78. }
  79. /**
  80. * Add replace markers.
  81. * @param $a array of markers as key => value
  82. * @return true on success or false on error
  83. */
  84. public function addMarkers ($a)
  85. {
  86. if(empty($a) || !is_array($a))
  87. return false;
  88. $this->aMarkers = array_merge($this->aMarkers, $a);
  89. return true;
  90. }
  91. public function removeActions()
  92. {
  93. $this->aActions = array();
  94. }
  95. public function bookmark()
  96. {
  97. $bResult = $this->oDb->bookmark($this->aPage);
  98. if(!$bResult)
  99. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  100. $oTemplate = BxDolStudioTemplate::getInstance();
  101. return array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  102. }
  103. protected function getSystemName($sValue)
  104. {
  105. return BxDolStudioUtils::getSystemName($sValue);
  106. }
  107. protected function getClassName($sValue)
  108. {
  109. return BxDolStudioUtils::getClassName($sValue);
  110. }
  111. protected function getModuleTitle($sName)
  112. {
  113. return BxDolStudioUtils::getModuleTitle($sName);
  114. }
  115. protected function getModuleIcon($sName, $sType = 'menu', $bReturnAsUrl = true)
  116. {
  117. return BxDolStudioUtils::getModuleIcon($sName, $sType, $bReturnAsUrl);
  118. }
  119. protected function getModules($bShowCustom = true, $bShowSystem = true)
  120. {
  121. return BxDolStudioUtils::getModules($bShowCustom, $bShowSystem);
  122. }
  123. protected function updateHistory()
  124. {
  125. if(empty($this->aPage['wid_id']))
  126. return;
  127. $sHistorySessionKey = BxTemplStudioMenuTop::$sHistorySessionKey;
  128. $iHistoryLength = BxTemplStudioMenuTop::$iHistoryLength;
  129. $oSession = BxDolSession::getInstance();
  130. $aHistory = $oSession->getValue($sHistorySessionKey);
  131. if(!empty($aHistory) && isset($aHistory[$this->aPage['name']]))
  132. unset($aHistory[$this->aPage['name']]);
  133. $aHistory[$this->aPage['name']] = array(
  134. 'name' => $this->aPage['name'],
  135. 'icon' => $this->aPage['wid_icon'],
  136. 'link' => $this->aPage['wid_url'],
  137. 'onclick' => $this->aPage['wid_click'],
  138. 'title' => $this->aPage['wid_caption']
  139. );
  140. if(count($aHistory) > $iHistoryLength)
  141. $aHistory = array_slice($aHistory, -$iHistoryLength);
  142. $oSession->setValue($sHistorySessionKey, $aHistory);
  143. }
  144. }
  145. /** @} */