BxDolStudioMenuTop.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 implements iBxDolSingleton
  16. {
  17. public static $sHistorySessionKey = 'sys_studio_history';
  18. public static $iHistoryLength = 5;
  19. public static $iToolbarLength = 10;
  20. protected $sPageName;
  21. protected $aItems;
  22. protected $aVisible;
  23. protected $aSelected;
  24. public function __construct()
  25. {
  26. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  27. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  28. parent::__construct();
  29. $this->sPageName = '';
  30. $this->aVisible = array(
  31. BX_DOL_STUDIO_MT_LEFT => getParam('sys_std_show_header_left') == 'on',
  32. BX_DOL_STUDIO_MT_CENTER => getParam('sys_std_show_header_center') == 'on',
  33. BX_DOL_STUDIO_MT_RIGHT => getParam('sys_std_show_header_right') == 'on',
  34. );
  35. $this->aSelected = array(
  36. BX_DOL_STUDIO_MT_LEFT => '',
  37. BX_DOL_STUDIO_MT_CENTER => '',
  38. BX_DOL_STUDIO_MT_RIGHT => ''
  39. );
  40. $this->aItems = array(
  41. BX_DOL_STUDIO_MT_LEFT => '',
  42. BX_DOL_STUDIO_MT_CENTER => '',
  43. BX_DOL_STUDIO_MT_RIGHT => ''
  44. );
  45. $this->aItems[BX_DOL_STUDIO_MT_LEFT] = BxTemplStudioFunctions::getInstance()->getLogo();
  46. $this->aItems[BX_DOL_STUDIO_MT_CENTER] = array(
  47. 'template' => 'menu_top_center.html',
  48. 'menu_items' => array(
  49. 'launcher' => array(
  50. 'name' => 'launcher',
  51. 'icon' => 'wi-launcher.svg',
  52. 'link' => '{url_studio}',
  53. 'title' => '_adm_tmi_cpt_launcher'
  54. )
  55. )
  56. );
  57. //--- Get Featured
  58. $aMenuItems = array();
  59. $oRolesUtils = BxDolStudioRolesUtils::getInstance();
  60. $oWidgetsDb = BxDolStudioWidgetsQuery::getInstance();
  61. $aFeatured = $oWidgetsDb->getWidgets(array('type' => 'all_featured', 'featured' => 1));
  62. foreach($aFeatured as $aItem)
  63. if(empty($aItem['type']) || $oRolesUtils->isActionAllowed('use ' . $aItem['type']))
  64. $aMenuItems[$aItem['page_name']] = array(
  65. 'class' => 'bx-menu-item-static',
  66. 'name' => $aItem['page_name'],
  67. 'icon' => $aItem['icon'],
  68. 'link' => $aItem['url'],
  69. 'onclick' => $aItem['click'],
  70. 'title' => $aItem['caption']
  71. );
  72. //--- Get Bookmarks
  73. $aBookmarks = $oWidgetsDb->getWidgets(array('type' => 'all_bookmarks', 'bookmark' => 1, 'profile_id' => bx_get_logged_profile_id()));
  74. foreach($aBookmarks as $aBookmark) {
  75. if(array_key_exists($aBookmark['page_name'], $aMenuItems))
  76. continue;
  77. if(!empty($aBookmark['type']) && !$oRolesUtils->isActionAllowed('use ' . $aBookmark['type']))
  78. continue;
  79. $aMenuItems[$aBookmark['page_name']] = array(
  80. 'class' => 'bx-menu-item-static',
  81. 'name' => $aBookmark['page_name'],
  82. 'icon' => $aBookmark['icon'],
  83. 'link' => $aBookmark['url'],
  84. 'onclick' => $aBookmark['click'],
  85. 'title' => $aBookmark['caption']
  86. );
  87. }
  88. //--- Get History
  89. $aHistory = self::historyGetList();
  90. if(!empty($aHistory) && is_array($aHistory))
  91. foreach($aHistory as $sPageName => $aMenuItem) {
  92. if(array_key_exists($sPageName, $aMenuItems))
  93. continue;
  94. $aMenuItem['class'] = 'bx-menu-item-dynamic';
  95. $aMenuItems[$sPageName] = $aMenuItem;
  96. }
  97. if(!empty($aMenuItems) && is_array($aMenuItems)) {
  98. if(count($aMenuItems) > BxTemplStudioMenuTop::$iToolbarLength)
  99. $aMenuItems = array_slice($aMenuItems, 0, BxTemplStudioMenuTop::$iToolbarLength);
  100. $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'] = bx_array_insert_after($aMenuItems, $this->aItems[BX_DOL_STUDIO_MT_CENTER]['menu_items'], 'launcher');
  101. }
  102. }
  103. public static function getInstance()
  104. {
  105. if (!isset($GLOBALS['bxDolClasses']['BxBaseStudioMenuTop']))
  106. $GLOBALS['bxDolClasses']['BxBaseStudioMenuTop'] = new BxTemplStudioMenuTop();
  107. return $GLOBALS['bxDolClasses']['BxBaseStudioMenuTop'];
  108. }
  109. public static function historyGetList()
  110. {
  111. $aHistory = BxDolSession::getInstance()->getValue(self::$sHistorySessionKey);
  112. if(empty($aHistory) || !is_array($aHistory))
  113. return array();
  114. if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength)
  115. $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength);
  116. return array_reverse($aHistory);
  117. }
  118. public static function historyAdd($aPage)
  119. {
  120. $oSession = BxDolSession::getInstance();
  121. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  122. if(!empty($aHistory) && isset($aHistory[$aPage['name']]))
  123. return;
  124. if (!is_array($aHistory))
  125. $aHistory = [];
  126. $aHistory[$aPage['name']] = array(
  127. 'name' => $aPage['name'],
  128. 'icon' => $aPage['wid_icon'],
  129. 'link' => $aPage['wid_url'],
  130. 'onclick' => $aPage['wid_click'],
  131. 'title' => $aPage['wid_caption']
  132. );
  133. if(count($aHistory) > BxTemplStudioMenuTop::$iHistoryLength)
  134. $aHistory = array_slice($aHistory, -BxTemplStudioMenuTop::$iHistoryLength);
  135. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  136. }
  137. public static function historyDelete($mixedPage)
  138. {
  139. if(is_array($mixedPage)) {
  140. if(!isset($mixedPage['name']))
  141. return;
  142. $mixedPage = $mixedPage['name'];
  143. }
  144. $oSession = BxDolSession::getInstance();
  145. $aHistory = $oSession->getValue(self::$sHistorySessionKey);
  146. if(empty($aHistory) || !isset($aHistory[$mixedPage]))
  147. return;
  148. unset($aHistory[$mixedPage]);
  149. $oSession->setValue(self::$sHistorySessionKey, $aHistory);
  150. }
  151. public function setPageName($sName)
  152. {
  153. $this->sPageName = $sName;
  154. }
  155. public function setContent($sPosition, $mixedContent)
  156. {
  157. $this->aItems[$sPosition] = $mixedContent;
  158. }
  159. public function setSelected($sPosition, $sValue)
  160. {
  161. if(!isset($this->aItems[$sPosition]['menu_items'][$sValue]))
  162. return;
  163. $this->aItems[$sPosition]['menu_items'][$sValue]['selected'] = true;
  164. }
  165. public function setVisible($sPosition, $bValue = true)
  166. {
  167. $this->aVisible[$sPosition] = $bValue;
  168. }
  169. public function setVisibleAll($bValue = true)
  170. {
  171. $this->aVisible = array(
  172. BX_DOL_STUDIO_MT_LEFT => $bValue,
  173. BX_DOL_STUDIO_MT_CENTER => $bValue,
  174. BX_DOL_STUDIO_MT_RIGHT => $bValue
  175. );
  176. }
  177. }
  178. /** @} */