BxBaseStudioMenuTop.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 UnaView UNA Studio Representation classes
  7. * @ingroup UnaStudio
  8. * @{
  9. */
  10. class BxBaseStudioMenuTop extends BxDolStudioMenuTop
  11. {
  12. function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. function getCss()
  17. {
  18. return array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flag-icons/css/|flag-icons.min.css', 'menu_top.css');
  19. }
  20. function getJs()
  21. {
  22. // the dock's app items are context menu triggers on every Studio page, and the menu's actions (activate, uninstall)
  23. // run through the module JS object, so its script comes with the menu wherever the page itself does not load it
  24. return array_merge(BxTemplStudioModules::getInstance()->getJs(), array('menu_top.js', 'context_menu.js'));
  25. }
  26. function getJsObject()
  27. {
  28. return 'oBxDolStudioMenuTop';
  29. }
  30. function getCode()
  31. {
  32. $oTemplate = BxDolStudioTemplate::getInstance();
  33. $aTmplVars = array();
  34. foreach($this->aItems as $sPosition => $mixedItems) {
  35. if(!$this->aVisible[$sPosition])
  36. continue;
  37. $sContent = "";
  38. if(is_string($mixedItems) && !empty($mixedItems))
  39. $sContent = $mixedItems;
  40. else if(is_array($mixedItems)) {
  41. $oMenu = new BxTemplStudioMenu($mixedItems);
  42. $oMenu->addMarkers(array(
  43. 'js_object' => $this->getJsObject(),
  44. 'url_root' => BX_DOL_URL_ROOT,
  45. 'url_studio' => BX_DOL_URL_STUDIO
  46. ));
  47. $sContent = $oMenu->getCode();
  48. if($sPosition == BX_DOL_STUDIO_MT_RIGHT) {
  49. $sContent = $oTemplate->parseHtmlByContent($sContent, [
  50. 'bx_if:show_search' => [
  51. 'condition' => $this->sPageName == 'home' && getParam('sys_std_show_header_right_search') == 'on',
  52. 'content' => [
  53. 'bx_if:show_active' => [
  54. 'condition' => false,
  55. 'content' => []
  56. ]
  57. ]
  58. ]
  59. ]);
  60. }
  61. }
  62. $aTmplVars[] = array(
  63. 'name' => $sPosition,
  64. 'content' => $sContent
  65. );
  66. }
  67. if(empty($aTmplVars))
  68. return '';
  69. $oTemplate->addJs($this->getJs());
  70. $oTemplate->addCss($this->getCss());
  71. return $oTemplate->parseHtmlByName('menu_top.html', array(
  72. 'bx_repeat:menus' => $aTmplVars,
  73. 'js_code_module' => BxTemplStudioModules::getInstance()->getJsCode(array(), false) // pages with their own instance define it again below
  74. ));
  75. }
  76. }
  77. /** @} */