BxDolDesigns.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. public static $fLogoAspectRatioDefault = 1.0;
  12. public static $fMarkAspectRatioDefault = 1.0;
  13. protected $sDesign;
  14. protected $oDesign;
  15. protected $aParams;
  16. protected $aValues;
  17. protected $sLogoStorage;
  18. protected $sLogoTranscoder;
  19. protected function __construct()
  20. {
  21. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  22. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  23. parent::__construct();
  24. $this->sLogoStorage = 'sys_images_custom';
  25. $this->sLogoTranscoder = 'sys_custom_images';
  26. }
  27. /**
  28. * Prevent cloning the instance
  29. */
  30. public function __clone()
  31. {
  32. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  33. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  34. }
  35. /**
  36. * Get singleton instance of the class
  37. */
  38. static function getInstance()
  39. {
  40. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  41. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolDesigns();
  42. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  43. }
  44. return $GLOBALS['bxDolClasses'][__CLASS__];
  45. }
  46. protected function init()
  47. {
  48. $this->sDesign = BxDolTemplate::getInstance()->getCode();
  49. $aDesign = BxDolModuleQuery::getInstance()->getModuleByUri($this->sDesign);
  50. if(!empty($aDesign) && is_array($aDesign))
  51. $this->oDesign = BxDolModule::getInstance($aDesign['name']);
  52. //--- Init site's logo params.
  53. if($this->oDesign instanceof BxDolModule && method_exists($this->oDesign->_oConfig, 'getLogoParams')) {
  54. list(
  55. $this->aParams['logo'],
  56. $this->aParams['mark'],
  57. $this->aParams['logo_alt']
  58. ) = $this->oDesign->_oConfig->getLogoParams();
  59. list(
  60. $this->aValues['logo_width'],
  61. $this->aValues['logo_height'],
  62. $this->aValues['logo_aspect_ratio'],
  63. $this->aValues['mark_width'],
  64. $this->aValues['mark_height'],
  65. $this->aValues['mark_aspect_ratio']
  66. ) = $this->oDesign->_oConfig->getLogoValues($this->getSiteLogoUrl(), $this->getSiteLogoInfo(), $this->getSiteMarkUrl(), $this->getSiteMarkInfo());
  67. }
  68. }
  69. public function getSiteLogo()
  70. {
  71. return $this->getSiteLogoParam('logo');
  72. }
  73. public function getSiteLogoUrl($iFileId = 0, $bOriginal = true)
  74. {
  75. if(!$iFileId)
  76. $iFileId = (int)$this->getSiteLogo();
  77. if(!$iFileId)
  78. return false;
  79. if($bOriginal)
  80. return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFileUrlById($iFileId);
  81. $aParams = [];
  82. if(($iLogoWidth = (int)$this->getSiteLogoWidth()) > 0)
  83. $aParams['x'] = $iLogoWidth;
  84. if(($iLogoHeight = (int)$this->getSiteLogoHeight()) > 0)
  85. $aParams['y'] = $iLogoHeight;
  86. if(!empty($aParams))
  87. $sFileUrl = BX_DOL_URL_ROOT . bx_append_url_params('image_transcoder.php', array_merge(array('o' => $this->sLogoTranscoder, 'h' => $iFileId), $aParams));
  88. else
  89. $sFileUrl = BxDolTranscoder::getObjectInstance($this->sLogoTranscoder)->getFileUrl($iFileId);
  90. return !empty($sFileUrl) ? $sFileUrl : false;
  91. }
  92. public function getSiteMark()
  93. {
  94. return $this->getSiteLogoParam('mark');
  95. }
  96. public function getSiteMarkUrl($iFileId = 0, $bOriginal = true)
  97. {
  98. if(!$iFileId)
  99. $iFileId = (int)$this->getSiteMark();
  100. if(!$iFileId)
  101. return false;
  102. return $this->getSiteLogoUrl($iFileId, $bOriginal);
  103. }
  104. public function getSiteLogoInfo($iFileId = 0)
  105. {
  106. if(!$iFileId)
  107. $iFileId = (int)$this->getSiteLogo();
  108. if(!$iFileId)
  109. return false;
  110. return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFile($iFileId);
  111. }
  112. public function getSiteMarkInfo($iFileId = 0)
  113. {
  114. if(!$iFileId)
  115. $iFileId = (int)$this->getSiteMark();
  116. if(!$iFileId)
  117. return false;
  118. return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFile($iFileId);
  119. }
  120. public function getSiteLogoAlt()
  121. {
  122. return $this->getSiteLogoParam('logo_alt');
  123. }
  124. public function getSiteLogoWidth()
  125. {
  126. return ($iResult = $this->getSiteLogoValue('logo_width')) !== false ? $iResult : 0;
  127. }
  128. public function getSiteLogoHeight()
  129. {
  130. return ($iResult = $this->getSiteLogoValue('logo_height')) !== false ? $iResult : 0;
  131. }
  132. public function getSiteMarkWidth()
  133. {
  134. return ($iResult = $this->getSiteLogoValue('mark_width')) !== false ? $iResult : 0;
  135. }
  136. public function getSiteMarkHeight()
  137. {
  138. return ($iResult = $this->getSiteLogoValue('mark_height')) !== false ? $iResult : 0;
  139. }
  140. protected function getSiteLogoParam($sName, $bGetSystem = false)
  141. {
  142. if(!empty($this->aParams[$sName]) && !$bGetSystem) {
  143. $sResult = getParam($this->aParams[$sName]);
  144. if(!empty($sResult))
  145. return $sResult;
  146. }
  147. return getParam('sys_site_' . $sName);
  148. }
  149. protected function getSiteLogoValue($sName)
  150. {
  151. return isset($this->aValues[$sName]) ? $this->aValues[$sName] : false;
  152. }
  153. }
  154. /** @} */