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