BxBaseStudioMenuAccountPopup.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 BxBaseStudioMenuAccountPopup extends BxDolStudioMenuAccountPopup
  11. {
  12. public function __construct ($aObject, $oTemplate)
  13. {
  14. parent::__construct ($aObject, $oTemplate);
  15. $this->_aObject['template'] = 'menu_account_popup.html';
  16. $this->addMarkers(array(
  17. 'js_object' => BxTemplStudioMenuTop::getInstance()->getJsObject(),
  18. 'url_root' => BX_DOL_URL_ROOT,
  19. 'url_studio' => BX_DOL_URL_STUDIO
  20. ));
  21. }
  22. /**
  23. * The signed-in name is rendered as a label, the theme and sounds items as segmented controls, and Manage Apps (it
  24. * switches edit mode on the launcher) as a toggle button; everything else stays a link.
  25. * The tour item follows the 'site_tour_studio' setting, like the launcher tour itself.
  26. */
  27. protected function _getMenuItem ($aItem)
  28. {
  29. if($aItem['name'] == 'tour' && getParam('site_tour_studio') != 'on')
  30. return false;
  31. if($aItem['name'] == 'sounds' && !BxDolSounds::getInstance()->isOn('studio'))
  32. return false;
  33. $aItem = parent::_getMenuItem($aItem);
  34. if($aItem === false)
  35. return $aItem;
  36. $sName = $aItem['name'];
  37. // Pre-render everything the blocks need as plain strings: the parser can't nest same-named bx_if blocks.
  38. $aContent = [
  39. 'class_add' => $aItem['class_add'],
  40. 'title' => $aItem['title'],
  41. 'link' => $aItem['link'],
  42. 'attrs' => $aItem['attrs'],
  43. 'onclick_attr' => !empty($aItem['onclick']) ? 'onclick="' . bx_html_attribute($aItem['onclick']) . '"' : '',
  44. 'icon_html' => $aItem['bx_if:image_inline']['condition'] ? $aItem['bx_if:image_inline']['content']['image'] : $this->getMenuIconHtml($aItem['icon']),
  45. ];
  46. if($sName == 'scheme')
  47. $aContent = array_merge($aContent, [
  48. 'js_object' => BxTemplStudioMenuTop::getInstance()->getJsObject(),
  49. 'title_auto' => bx_html_attribute(_t('_sys_menu_item_title_sa_scheme_auto')),
  50. 'title_light' => bx_html_attribute(_t('_sys_menu_item_title_sa_scheme_light')),
  51. 'title_dark' => bx_html_attribute(_t('_sys_menu_item_title_sa_scheme_dark')),
  52. ]);
  53. // The visitor's level of interface sounds; bx_sound_mark_switches() checks the current one.
  54. if($sName == 'sounds')
  55. $aContent = array_merge($aContent, [
  56. 'title_off' => bx_html_attribute(_t('_sys_txt_sounds_level_off')),
  57. 'title_quiet' => bx_html_attribute(_t('_sys_txt_sounds_level_quiet')),
  58. 'title_full' => bx_html_attribute(_t('_sys_txt_sounds_level_full')),
  59. ]);
  60. $aBlocks = [
  61. 'show_label' => $sName == 'account',
  62. 'show_theme' => $sName == 'scheme',
  63. 'show_sounds' => $sName == 'sounds',
  64. 'show_button' => $sName == 'edit',
  65. 'show_link' => !in_array($sName, ['account', 'scheme', 'edit', 'sounds']),
  66. ];
  67. foreach($aBlocks as $sBlock => $bCondition)
  68. $aItem['bx_if:' . $sBlock] = [
  69. 'condition' => $bCondition,
  70. 'content' => $bCondition ? $aContent : []
  71. ];
  72. return $aItem;
  73. }
  74. }
  75. /** @} */