1
0

BxBaseStudioMenu.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 BxBaseStudioMenu extends BxDolStudioMenu
  11. {
  12. protected $_bMenuSide;
  13. protected $_bMenuToolbar;
  14. protected $_bInlineIcons;
  15. public function __construct ($aObject, $oTemplate)
  16. {
  17. parent::__construct ($aObject, $oTemplate);
  18. $this->_bMenuSide = $this->_aObject['template'] == 'menu_side.html';
  19. $this->_bMenuToolbar = $this->_aObject['template'] == 'menu_top_toolbar.html';
  20. $this->_bInlineIcons = in_array($this->_aObject['template'], array(
  21. 'menu_side.html',
  22. 'menu_top_toolbar.html',
  23. 'menu_launcher_browser.html',
  24. 'page_breadcrumb.html'
  25. ));
  26. }
  27. public function setInlineIcons($bInlineIcons)
  28. {
  29. $this->_bInlineIcons = $bInlineIcons;
  30. }
  31. protected function _getMenuItem ($aItem)
  32. {
  33. $aItem = parent::_getMenuItem($aItem);
  34. if($aItem === false)
  35. return $aItem;
  36. $aItem['class'] = isset($aItem['class']) ? $aItem['class'] : '';
  37. if(!isset($aItem['class_add']))
  38. $aItem['class_add'] = '';
  39. $aItem['class_add'] .= ' ' . str_replace('_', '-', $aItem['name']);
  40. // an item may keep its icon as an <img> (icon_inline => false): app tile artwork stays out of the document and its gradient ids never collide
  41. if($this->_bInlineIcons && ($aItem['icon_inline'] ?? true) && $aItem['bx_if:image']['condition'] && ($sImage = $this->_oTemplate->getIconContent($aItem['icon'])) !== false)
  42. $aItem = array_merge($aItem, [
  43. 'bx_if:image' => [
  44. 'condition' => false,
  45. 'content' => [],
  46. ],
  47. 'bx_if:image_inline' => [
  48. 'condition' => true,
  49. 'content' => [
  50. 'image' => $sImage
  51. ],
  52. ],
  53. ]);
  54. if($this->_bMenuSide) {
  55. $aItem['bx_if:show_icon'] = [
  56. 'condition' => $aItem['bx_if:icon']['condition'] || $aItem['bx_if:image']['condition'] || $aItem['bx_if:image_inline']['condition'],
  57. 'content' => []
  58. ];
  59. $aItem['bx_if:show_icon_bg'] = [
  60. 'condition' => (isset($aItem['icon_bg']) && $aItem['icon_bg'] === true) || strpos($aItem['icon'], '.') === false,
  61. 'content' => []
  62. ];
  63. }
  64. if(!$this->_bMenuToolbar)
  65. return $aItem;
  66. /*
  67. * Header toolbar: an item that only runs a script is a button, not a link. The template renders the two differently,
  68. * so it gets everything pre-rendered, because a bx_if block only sees its own content.
  69. */
  70. $bButton = empty($aItem['link']) || strncmp($aItem['link'], 'javascript:', 11) === 0;
  71. $sIconHtml = '';
  72. if($aItem['bx_if:icon']['condition'])
  73. $sIconHtml = '<i class="sys-icon ' . $aItem['bx_if:icon']['content']['icon'] . ' bx-def-round-corners bx-def-font-contrasted"></i>';
  74. else if($aItem['bx_if:image']['condition'])
  75. $sIconHtml = '<img src="' . $aItem['bx_if:image']['content']['icon_url'] . '" alt="" />';
  76. else if($aItem['bx_if:image_inline']['condition'])
  77. $sIconHtml = $aItem['bx_if:image_inline']['content']['image'];
  78. $aContent = [
  79. 'name' => $aItem['name'],
  80. 'link' => $aItem['link'],
  81. 'onclick' => !empty($aItem['onclick']) ? $aItem['onclick'] : '',
  82. 'title' => isset($aItem['title_attr']) ? $aItem['title_attr'] : bx_html_attribute($aItem['title']),
  83. 'attrs' => $aItem['attrs'],
  84. 'icon_html' => $sIconHtml,
  85. ];
  86. $aItem['bx_if:is_link'] = ['condition' => !$bButton, 'content' => $aContent];
  87. $aItem['bx_if:is_button'] = ['condition' => $bButton, 'content' => $aContent];
  88. return $aItem;
  89. }
  90. /**
  91. * Check if menu items is selected.
  92. * @param $a menu item array
  93. * @return boolean
  94. */
  95. protected function _isSelected ($a)
  96. {
  97. return isset($a['selected']) && $a['selected'] === true;
  98. }
  99. }
  100. /** @} */