1
0

BxTemplFunctions.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 UnaTemplate UNA Template Classes
  7. * @{
  8. */
  9. class BxTemplFunctions extends BxBaseFunctions
  10. {
  11. public function __construct($oTemplate = null)
  12. {
  13. parent::__construct($oTemplate);
  14. }
  15. function getMainLogo($aParams = array())
  16. {
  17. $oDesigns = BxDolDesigns::getInstance();
  18. $sTitle = getParam('site_title');
  19. $bTitle = !empty($sTitle);
  20. $sAlt = $oDesigns->getSiteLogoAlt();
  21. if(empty($sAlt) && $bTitle)
  22. $sAlt = $sTitle;
  23. $sAltAttr = bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE);
  24. $bTmplVarsShowTitle = $bTitle;
  25. $aTmplVarsShowImage = [];
  26. $aTmplVarsShowImageMini = [];
  27. $bDefault = false;
  28. if(($sFileUrl = $this->getMainLogoUrl()) !== false || ($bDefault = (!$bTitle && ($sFileUrl = $this->_oTemplate->getImageUrl('logo-generic.svg')) != ''))) {
  29. $iLogoWidth = (int)$oDesigns->getSiteLogoWidth();
  30. $sMaxWidth = $iLogoWidth > 0 ? 'max-width:' . round($iLogoWidth/16, 3) . 'rem;' : '';
  31. $iLogoHeight = (int)$oDesigns->getSiteLogoHeight();
  32. $sMaxHeight = $iLogoHeight > 0 ? 'max-height:' . round($iLogoHeight/16, 3) . 'rem;' : '';
  33. $bTmplVarsShowTitle = false;
  34. $aTmplVarsShowImage = [
  35. 'class' => '',
  36. 'style' => $sMaxWidth . $sMaxHeight,
  37. 'src' => $sFileUrl,
  38. 'alt' => $sAltAttr
  39. ];
  40. if($bDefault) {
  41. $aTmplVarsShowImage['class'] = 'hidden lg:block';
  42. if(($sFileUrl = $this->_oTemplate->getImageUrl('mark-generic.svg')) != '')
  43. $aTmplVarsShowImageMini = [
  44. 'class' => 'block lg:hidden',
  45. 'style' => $sMaxWidth . $sMaxHeight,
  46. 'src' => $sFileUrl,
  47. 'alt' => $sAltAttr
  48. ];
  49. }
  50. }
  51. $aAttrs = [
  52. 'href' => BX_DOL_URL_ROOT,
  53. 'title' => $sAltAttr
  54. ];
  55. if(!empty($aParams['attrs']) && is_array($aParams['attrs']))
  56. $aAttrs = array_merge($aAttrs, $aParams['attrs']);
  57. return $this->_oTemplate->parseHtmlByName('logo_main.html', [
  58. 'attrs' => bx_convert_array2attrs($aAttrs),
  59. 'bx_if:show_title' => [
  60. 'condition' => $bTmplVarsShowTitle,
  61. 'content' => [
  62. 'logo' => $sTitle,
  63. ]
  64. ],
  65. 'bx_if:show_image' => [
  66. 'condition' => !empty($aTmplVarsShowImage),
  67. 'content' => $aTmplVarsShowImage
  68. ],
  69. 'bx_if:show_image_mini' => [
  70. 'condition' => !empty($aTmplVarsShowImageMini),
  71. 'content' => $aTmplVarsShowImageMini
  72. ]
  73. ]);
  74. }
  75. public function TemplPageAddComponent($sKey)
  76. {
  77. switch( $sKey ) {
  78. case 'sys_site_search':
  79. $oSearch = new BxTemplSearch();
  80. $oSearch->setLiveSearch(true);
  81. return $oSearch->getForm(BX_DB_PADDING_DEF, false, true) . $oSearch->getResultsContainer();
  82. default:
  83. return parent::TemplPageAddComponent($sKey);
  84. }
  85. }
  86. protected function getInjFooterPopupMenus()
  87. {
  88. $sContent = '';
  89. $oSearch = new BxTemplSearch();
  90. $oSearch->setLiveSearch(true);
  91. $sContent .= $this->_oTemplate->parsePageByName('search.html', array(
  92. 'search_form' => $oSearch->getForm(BX_DB_CONTENT_ONLY),
  93. 'results' => $oSearch->getResultsContainer(),
  94. ));
  95. if(isLogged()) {
  96. $sContent .= $this->_oTemplate->getMenu('sys_add_content');
  97. $sContent .= $this->_oTemplate->getMenu('sys_account_popup');
  98. }
  99. return $sContent;
  100. }
  101. protected function getInjFooterSidebarSite()
  102. {
  103. $oSearch = new BxTemplSearch();
  104. $oSearch->setLiveSearch(true);
  105. $sSearch = $oSearch->getForm(BX_DB_CONTENT_ONLY);
  106. $sLogoUrl = $this->getMainLogoUrl();
  107. $bLogoUrl = !empty($sLogoUrl);
  108. $sLogoText = BxDolDesigns::getInstance()->getSiteLogoAlt();
  109. if(empty($sLogoText))
  110. $sLogoText = getParam('site_title');
  111. return $this->_oTemplate->parsePageByName('sidebar_site.html', array(
  112. 'bx_if:show_logo_image' => array(
  113. 'condition' => $bLogoUrl,
  114. 'content' => array(
  115. 'logo_url' => $sLogoUrl,
  116. 'logo_text' => $sLogoText
  117. )
  118. ),
  119. 'bx_if:show_logo_text' => array(
  120. 'condition' => !$bLogoUrl,
  121. 'content' => array(
  122. 'logo_text' => $sLogoText
  123. )
  124. ),
  125. 'search_form' => $sSearch,
  126. ));
  127. }
  128. protected function getInjFooterSidebarAccount()
  129. {
  130. $oProfile = BxDolProfile::getInstance();
  131. if(!$oProfile)
  132. return '';
  133. $sSwitcher = '';
  134. if(($aSwitcher = bx_srv('system', 'account_profile_switcher', [], 'TemplServiceProfiles')) !== false)
  135. $sSwitcher = $aSwitcher['content'];
  136. return $this->_oTemplate->parsePageByName('sidebar_account.html', [
  137. 'active_profile' => $oProfile->getUnit(),
  138. 'menu_notifications' => BxDolMenu::getObjectInstance('sys_account_notifications')->getCode(),
  139. 'profile_switcher' => $sSwitcher,
  140. 'bx_if:multiple_profiles_mode' => [
  141. 'condition' => BxDolAccount::isAllowedCreateMultiple($oProfile->id()),
  142. 'content' => [
  143. 'url_switch_profile' => BxDolPermalinks::getInstance()->permalink('page.php?i=account-profile-switcher')
  144. ]
  145. ]
  146. ]);
  147. }
  148. }
  149. /** @} */