BxDolDesigns.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
  10. {
  11. protected $sDesign;
  12. protected $oDesign;
  13. protected $aParams;
  14. protected function __construct()
  15. {
  16. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  17. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  18. parent::__construct();
  19. }
  20. /**
  21. * Prevent cloning the instance
  22. */
  23. public function __clone()
  24. {
  25. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  26. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  27. }
  28. /**
  29. * Get singleton instance of the class
  30. */
  31. static function getInstance()
  32. {
  33. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  34. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolDesigns();
  35. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  36. }
  37. return $GLOBALS['bxDolClasses'][__CLASS__];
  38. }
  39. protected function init()
  40. {
  41. $this->sDesign = BxDolTemplate::getInstance()->getCode();
  42. $aDesign = BxDolModuleQuery::getInstance()->getModuleByUri($this->sDesign);
  43. if(!empty($aDesign) && is_array($aDesign))
  44. $this->oDesign = BxDolModule::getInstance($aDesign['name']);
  45. //--- Init site's logo params.
  46. if($this->oDesign instanceof BxDolModule && method_exists($this->oDesign->_oConfig, 'getLogoParams'))
  47. list(
  48. $this->aParams['logo'],
  49. $this->aParams['logo_alt'],
  50. $this->aParams['logo_width'],
  51. $this->aParams['logo_height']
  52. ) = $this->oDesign->_oConfig->getLogoParams();
  53. }
  54. public function getSiteLogo()
  55. {
  56. return $this->getSiteLogoParam('logo');
  57. }
  58. public function getSiteLogoAlt()
  59. {
  60. return $this->getSiteLogoParam('logo_alt');
  61. }
  62. public function getSiteLogoWidth()
  63. {
  64. return $this->getSiteLogoParam('logo_width');
  65. }
  66. public function getSiteLogoHeight()
  67. {
  68. return $this->getSiteLogoParam('logo_height');
  69. }
  70. protected function getSiteLogoParam($sName)
  71. {
  72. if(!empty($this->aParams[$sName])) {
  73. $sResult = getParam($this->aParams[$sName]);
  74. if(!empty($sResult))
  75. return $sResult;
  76. }
  77. return getParam('sys_site_' . $sName);
  78. }
  79. }
  80. /** @} */