BxDolStudioMenuTop.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. 'site' => array(
  44. 'name' => 'site',
  45. 'icon' => 'home',
  46. 'link' => BX_DOL_URL_ROOT,
  47. 'title' => '_adm_tmi_cpt_site'
  48. ),
  49. 'launcher' => array(
  50. 'name' => 'launcher',
  51. 'icon' => 'th',
  52. 'link' => BX_DOL_URL_STUDIO,
  53. 'title' => '_adm_tmi_cpt_launcher'
  54. ),
  55. 'logout' => array(
  56. 'name' => 'logout',
  57. 'icon' => 'sign-out-alt',
  58. 'link' => 'logout.php',
  59. 'onclick' => $this->getJsObject() . '.clickLogout(this);',
  60. 'title' => '_adm_tmi_cpt_logout'
  61. )
  62. )
  63. );
  64. $aHistory = BxDolSession::getInstance()->getValue(self::$sHistorySessionKey);
  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'], 'logout');
  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 function setContent($sPosition, $mixedContent)
  102. {
  103. $this->aItems[$sPosition] = $mixedContent;
  104. }
  105. public function setSelected($sPosition, $sValue)
  106. {
  107. if(!isset($this->aItems[$sPosition]['menu_items'][$sValue]))
  108. return;
  109. $this->aItems[$sPosition]['menu_items'][$sValue]['selected'] = true;
  110. }
  111. public function setVisible($sPosition, $bValue = true)
  112. {
  113. $this->aVisible[$sPosition] = $bValue;
  114. }
  115. public function setVisibleAll($bValue = true)
  116. {
  117. $this->aVisible = array(
  118. BX_DOL_STUDIO_MT_LEFT => $bValue,
  119. BX_DOL_STUDIO_MT_CENTER => $bValue,
  120. BX_DOL_STUDIO_MT_RIGHT => $bValue
  121. );
  122. }
  123. }
  124. /** @} */