BxFontAwesomeModule.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 FontAwesome Font Awesome Pro integration
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxFontAwesomeModule extends BxDolModule
  12. {
  13. function __construct(&$aModule)
  14. {
  15. parent::__construct($aModule);
  16. }
  17. public function serviceSwitchFont($sFont)
  18. {
  19. $this->_oDb->switchFont($sFont);
  20. BxDolCacheUtilities::getInstance()->clear('css');
  21. BxDolCacheUtilities::getInstance()->clear('db');
  22. }
  23. public function serviceInjection()
  24. {
  25. // preload active font, so page will load faster
  26. $aMap = array(
  27. 'fonts-light.css' => array('fa-light-300.woff2'),
  28. 'fonts-duotone.css' => array('fa-duotone-900.woff2'),
  29. 'fonts-all.css' => array('fa-regular-400.woff2', 'fa-solid-900.woff2'),
  30. );
  31. $sCss = $this->_oDb->getActiveFont();
  32. if (!isset($aMap[$sCss]))
  33. return '';
  34. $aFonts = $aMap[$sCss];
  35. $s = '';
  36. foreach($aFonts as $sFont) {
  37. $sFontUrl = BX_DOL_URL_MODULES . 'boonex/fontawesome/template/fonts/' . $sFont;
  38. $s .= '<link rel="preload" as="font" type="font/woff2" crossorigin href="' . $sFontUrl . '" />';
  39. }
  40. return $s;
  41. }
  42. }
  43. /** @} */