BxDolStudioMenuTop.php 7.0 KB

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