BxBaseStudioMenuAccountPopup.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 item as a segmented control and Manage Apps as a toggle button
  24. * (it switches edit mode on the launcher); 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. $aItem = parent::_getMenuItem($aItem);
  32. if($aItem === false)
  33. return $aItem;
  34. $sName = $aItem['name'];
  35. // Pre-render everything the blocks need as plain strings: the parser can't nest same-named bx_if blocks.
  36. $aContent = [
  37. 'class_add' => $aItem['class_add'],
  38. 'title' => $aItem['title'],
  39. 'link' => $aItem['link'],
  40. 'attrs' => $aItem['attrs'],
  41. 'onclick_attr' => !empty($aItem['onclick']) ? 'onclick="' . bx_html_attribute($aItem['onclick']) . '"' : '',
  42. 'icon_html' => $aItem['bx_if:image_inline']['condition'] ? $aItem['bx_if:image_inline']['content']['image'] : $this->getMenuIconHtml($aItem['icon']),
  43. ];
  44. if($sName == 'scheme')
  45. $aContent = array_merge($aContent, [
  46. 'js_object' => BxTemplStudioMenuTop::getInstance()->getJsObject(),
  47. 'title_auto' => bx_html_attribute(_t('_sys_menu_item_title_sa_scheme_auto')),
  48. 'title_light' => bx_html_attribute(_t('_sys_menu_item_title_sa_scheme_light')),
  49. 'title_dark' => bx_html_attribute(_t('_sys_menu_item_title_sa_scheme_dark')),
  50. ]);
  51. $aBlocks = [
  52. 'show_label' => $sName == 'account',
  53. 'show_theme' => $sName == 'scheme',
  54. 'show_button' => $sName == 'edit',
  55. 'show_link' => !in_array($sName, ['account', 'scheme', 'edit']),
  56. ];
  57. foreach($aBlocks as $sBlock => $bCondition)
  58. $aItem['bx_if:' . $sBlock] = [
  59. 'condition' => $bCondition,
  60. 'content' => $bCondition ? $aContent : []
  61. ];
  62. return $aItem;
  63. }
  64. }
  65. /** @} */