BxDolStudioMenuTop.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. $this->aItems[BX_DOL_STUDIO_MT_CENTER] = bx_idn_to_utf8(BX_DOL_URL_ROOT, true);
  68. $this->aItems[BX_DOL_STUDIO_MT_RIGHT] = array(
  69. 'template' => 'menu_top_toolbar.html',
  70. 'menu_items' => array(
  71. 'edit' => array(
  72. 'name' => 'edit',
  73. 'icon' => 'magic',
  74. 'onclick' => $this->getJsObject() . '.clickEdit(this);',
  75. 'title' => '_adm_tmi_cpt_edit'
  76. ),
  77. 'favorite' => array(
  78. 'name' => 'favorite',
  79. 'icon' => 'star',
  80. 'onclick' => $this->getJsObject() . '.clickFavorite(this);',
  81. 'title' => '_adm_tmi_cpt_favorite'
  82. ),
  83. 'extensions' => array(
  84. 'name' => 'extensions',
  85. 'icon' => 'plus',
  86. 'link' => BX_DOL_URL_STUDIO . 'store.php?page=goodies',
  87. 'title' => '_adm_tmi_cpt_extensions'
  88. ),
  89. 'tour' => array(
  90. 'name' => 'tour',
  91. 'icon' => 'question',
  92. 'link' => 'javascript:void(0);',
  93. 'onclick' => 'glTour.start()',
  94. 'title' => '_adm_tmi_cpt_tour'
  95. )
  96. )
  97. );
  98. $aLanguages = BxDolLanguagesQuery::getInstance()->getLanguages(false, true);
  99. if(count($aLanguages) > 1)
  100. $this->aItems[BX_DOL_STUDIO_MT_RIGHT]['menu_items']['language'] = array(
  101. 'name' => 'language',
  102. 'icon' => 'language',
  103. 'link' => 'javascript:void(0);',
  104. 'onclick' => "bx_menu_popup('sys_switch_language_popup', this);",
  105. 'title' => '_adm_tmi_cpt_language'
  106. );
  107. }
  108. public static function historyGetList()
  109. {
  110. return BxDolSession::getInstance()->getValue(self::$sHistorySessionKey);
  111. }
  112. public static function historyAdd($aPage)
  113. {
  114. $oSession = BxDolSession::getInstance();
  115. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  116. if(!empty($aHistory) && isset($aHistory[$aPage['name']]))
  117. return;
  118. $aHistory[$aPage['name']] = array(
  119. 'name' => $aPage['name'],
  120. 'icon' => $aPage['wid_icon'],
  121. 'link' => $aPage['wid_url'],
  122. 'onclick' => $aPage['wid_click'],
  123. 'title' => $aPage['wid_caption']
  124. );
  125. if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength)
  126. $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength);
  127. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  128. }
  129. public static function historyDelete($mixedPage)
  130. {
  131. if(is_array($mixedPage)) {
  132. if(!isset($mixedPage['name']))
  133. return;
  134. $mixedPage = $mixedPage['name'];
  135. }
  136. $oSession = BxDolSession::getInstance();
  137. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  138. if(empty($aHistory) || !isset($aHistory[$mixedPage]))
  139. return;
  140. unset($aHistory[$mixedPage]);
  141. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  142. }
  143. public function setContent($sPosition, $mixedContent)
  144. {
  145. $this->aItems[$sPosition] = $mixedContent;
  146. }
  147. public function setSelected($sPosition, $sValue)
  148. {
  149. if(!isset($this->aItems[$sPosition]['menu_items'][$sValue]))
  150. return;
  151. $this->aItems[$sPosition]['menu_items'][$sValue]['selected'] = true;
  152. }
  153. public function setVisible($sPosition, $bValue = true)
  154. {
  155. $this->aVisible[$sPosition] = $bValue;
  156. }
  157. public function setVisibleAll($bValue = true)
  158. {
  159. $this->aVisible = array(
  160. BX_DOL_STUDIO_MT_LEFT => $bValue,
  161. BX_DOL_STUDIO_MT_CENTER => $bValue,
  162. BX_DOL_STUDIO_MT_RIGHT => $bValue
  163. );
  164. }
  165. }
  166. /** @} */