BxDolStudioMenuTop.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. $aLanguages = BxDolLanguagesQuery::getInstance()->getLanguages(false, true);
  101. if(count($aLanguages) > 1)
  102. $this->aItems[BX_DOL_STUDIO_MT_RIGHT]['menu_items']['language'] = array(
  103. 'name' => 'language',
  104. 'icon' => 'language',
  105. 'link' => 'javascript:void(0);',
  106. 'onclick' => "bx_menu_popup('sys_switch_language_popup', this);",
  107. 'title' => '_adm_tmi_cpt_language'
  108. );
  109. }
  110. public static function historyGetList()
  111. {
  112. return BxDolSession::getInstance()->getValue(self::$sHistorySessionKey);
  113. }
  114. public static function historyAdd($aPage)
  115. {
  116. $oSession = BxDolSession::getInstance();
  117. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  118. if(!empty($aHistory) && isset($aHistory[$aPage['name']]))
  119. return;
  120. $aHistory[$aPage['name']] = array(
  121. 'name' => $aPage['name'],
  122. 'icon' => $aPage['wid_icon'],
  123. 'link' => $aPage['wid_url'],
  124. 'onclick' => $aPage['wid_click'],
  125. 'title' => $aPage['wid_caption']
  126. );
  127. if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength)
  128. $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength);
  129. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  130. }
  131. public static function historyDelete($mixedPage)
  132. {
  133. if(is_array($mixedPage)) {
  134. if(!isset($mixedPage['name']))
  135. return;
  136. $mixedPage = $mixedPage['name'];
  137. }
  138. $oSession = BxDolSession::getInstance();
  139. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  140. if(empty($aHistory) || !isset($aHistory[$mixedPage]))
  141. return;
  142. unset($aHistory[$mixedPage]);
  143. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  144. }
  145. public function setContent($sPosition, $mixedContent)
  146. {
  147. $this->aItems[$sPosition] = $mixedContent;
  148. }
  149. public function setSelected($sPosition, $sValue)
  150. {
  151. if(!isset($this->aItems[$sPosition]['menu_items'][$sValue]))
  152. return;
  153. $this->aItems[$sPosition]['menu_items'][$sValue]['selected'] = true;
  154. }
  155. public function setVisible($sPosition, $bValue = true)
  156. {
  157. $this->aVisible[$sPosition] = $bValue;
  158. }
  159. public function setVisibleAll($bValue = true)
  160. {
  161. $this->aVisible = array(
  162. BX_DOL_STUDIO_MT_LEFT => $bValue,
  163. BX_DOL_STUDIO_MT_CENTER => $bValue,
  164. BX_DOL_STUDIO_MT_RIGHT => $bValue
  165. );
  166. }
  167. }
  168. /** @} */