BxDolStudioMenuTop.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. require_once(BX_DOL_DIR_STUDIO_INC . 'utils.inc.php');
  10. define('BX_DOL_STUDIO_MT_LEFT', 'left');
  11. define('BX_DOL_STUDIO_MT_CENTER', 'center');
  12. define('BX_DOL_STUDIO_MT_RIGHT', 'right');
  13. define('BX_DOL_STUDIO_MTB_CIRCLE', 'circ');
  14. define('BX_DOL_STUDIO_MTB_RECTANGLE', 'rect');
  15. class BxDolStudioMenuTop extends BxDol
  16. {
  17. public static $sHistorySessionKey = 'sys_studio_history';
  18. public static $iHistoryLength = 5;
  19. protected $aItems;
  20. protected $aVisible;
  21. protected $aSelected;
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. $this->aVisible = array(
  26. BX_DOL_STUDIO_MT_LEFT => true,
  27. BX_DOL_STUDIO_MT_CENTER => true,
  28. BX_DOL_STUDIO_MT_RIGHT => true
  29. );
  30. $this->aSelected = array(
  31. BX_DOL_STUDIO_MT_LEFT => '',
  32. BX_DOL_STUDIO_MT_CENTER => '',
  33. BX_DOL_STUDIO_MT_RIGHT => ''
  34. );
  35. $this->aItems = array(
  36. BX_DOL_STUDIO_MT_LEFT => '',
  37. BX_DOL_STUDIO_MT_CENTER => '',
  38. BX_DOL_STUDIO_MT_RIGHT => ''
  39. );
  40. $this->aItems[BX_DOL_STUDIO_MT_LEFT] = array(
  41. 'template' => 'menu_floating_blocks.html',
  42. 'menu_items' => array(
  43. 'launcher' => array(
  44. 'name' => 'launcher',
  45. 'icon' => 'th',
  46. 'link' => BX_DOL_URL_STUDIO,
  47. 'title' => '_adm_tmi_cpt_launcher'
  48. ),
  49. 'site' => array(
  50. 'name' => 'site',
  51. 'icon' => 'home',
  52. 'link' => BX_DOL_URL_ROOT,
  53. 'title' => '_adm_tmi_cpt_site'
  54. ),
  55. 'logout' => array(
  56. 'name' => 'logout',
  57. 'icon' => 'sign-out-alt',
  58. 'link' => BX_DOL_URL_ROOT . 'logout.php',
  59. 'onclick' => $this->getJsObject() . '.clickLogout(this);',
  60. 'title' => '_adm_tmi_cpt_logout'
  61. )
  62. )
  63. );
  64. $aHistory = self::historyGetList();
  65. if(!empty($aHistory) && is_array($aHistory))
  66. $this->aItems[BX_DOL_STUDIO_MT_LEFT]['menu_items'] = bx_array_insert_before(array_reverse($aHistory), $this->aItems[BX_DOL_STUDIO_MT_LEFT]['menu_items'], 'site');
  67. $aMatch = array();
  68. $iResult = preg_match("/^(https?:\/\/)?(.*)\/$/", BX_DOL_URL_ROOT, $aMatch);
  69. $this->aItems[BX_DOL_STUDIO_MT_CENTER] = $iResult ? $aMatch[2] : '';
  70. $this->aItems[BX_DOL_STUDIO_MT_RIGHT] = array(
  71. 'template' => 'menu_top_toolbar.html',
  72. 'menu_items' => array(
  73. 'edit' => array(
  74. 'name' => 'edit',
  75. 'icon' => 'magic',
  76. 'onclick' => $this->getJsObject() . '.clickEdit(this);',
  77. 'title' => '_adm_tmi_cpt_edit'
  78. ),
  79. 'favorite' => array(
  80. 'name' => 'favorite',
  81. 'icon' => 'star',
  82. 'onclick' => $this->getJsObject() . '.clickFavorite(this);',
  83. 'title' => '_adm_tmi_cpt_favorite'
  84. ),
  85. 'extensions' => array(
  86. 'name' => 'extensions',
  87. 'icon' => 'plus',
  88. 'link' => BX_DOL_URL_STUDIO . 'store.php?page=goodies',
  89. 'title' => '_adm_tmi_cpt_extensions'
  90. ),
  91. 'tour' => array(
  92. 'name' => 'tour',
  93. 'icon' => 'question',
  94. 'link' => 'javascript:void(0);',
  95. 'onclick' => 'glTour.start()',
  96. 'title' => '_adm_tmi_cpt_tour'
  97. )
  98. )
  99. );
  100. }
  101. public static function historyGetList()
  102. {
  103. return BxDolSession::getInstance()->getValue(self::$sHistorySessionKey);
  104. }
  105. public static function historyAdd($aPage)
  106. {
  107. $oSession = BxDolSession::getInstance();
  108. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  109. if(!empty($aHistory) && isset($aHistory[$aPage['name']]))
  110. return;
  111. $aHistory[$aPage['name']] = array(
  112. 'name' => $aPage['name'],
  113. 'icon' => $aPage['wid_icon'],
  114. 'link' => $aPage['wid_url'],
  115. 'onclick' => $aPage['wid_click'],
  116. 'title' => $aPage['wid_caption']
  117. );
  118. if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength)
  119. $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength);
  120. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  121. }
  122. public static function historyDelete($mixedPage)
  123. {
  124. if(is_array($mixedPage)) {
  125. if(!isset($mixedPage['name']))
  126. return;
  127. $mixedPage = $mixedPage['name'];
  128. }
  129. $oSession = BxDolSession::getInstance();
  130. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  131. if(empty($aHistory) || !isset($aHistory[$mixedPage]))
  132. return;
  133. unset($aHistory[$mixedPage]);
  134. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  135. }
  136. public function setContent($sPosition, $mixedContent)
  137. {
  138. $this->aItems[$sPosition] = $mixedContent;
  139. }
  140. public function setSelected($sPosition, $sValue)
  141. {
  142. if(!isset($this->aItems[$sPosition]['menu_items'][$sValue]))
  143. return;
  144. $this->aItems[$sPosition]['menu_items'][$sValue]['selected'] = true;
  145. }
  146. public function setVisible($sPosition, $bValue = true)
  147. {
  148. $this->aVisible[$sPosition] = $bValue;
  149. }
  150. public function setVisibleAll($bValue = true)
  151. {
  152. $this->aVisible = array(
  153. BX_DOL_STUDIO_MT_LEFT => $bValue,
  154. BX_DOL_STUDIO_MT_CENTER => $bValue,
  155. BX_DOL_STUDIO_MT_RIGHT => $bValue
  156. );
  157. }
  158. }
  159. /** @} */