BxTemplFunctions.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. }
  102. /** @} */