BxTemplFunctions.php 7.3 KB

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