BxDolDesigns.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. $this->aParams = $this->oDesign->_oConfig->getLogoParams();
  55. $this->aValues = $this->oDesign->_oConfig->getLogoValues('logo', $this->getSiteLogoUrl(), $this->getSiteLogoInfo());
  56. if(isset($this->aParams['logo_dark']))
  57. $this->aValues += $this->oDesign->_oConfig->getLogoValues('logo_dark', $this->getSiteLogoDarkUrl(), $this->getSiteLogoDarkInfo());
  58. $this->aValues += $this->oDesign->_oConfig->getLogoValues('mark', $this->getSiteMarkUrl(), $this->getSiteMarkInfo());
  59. if(isset($this->aParams['mark_dark']))
  60. $this->aValues += $this->oDesign->_oConfig->getLogoValues('mark_dark', $this->getSiteMarkDarkUrl(), $this->getSiteMarkDarkInfo());
  61. }
  62. }
  63. public static function getAspectRatioDefault($sType)
  64. {
  65. return in_array($sType, ['logo', 'logo_dark']) ? self::$fLogoAspectRatioDefault : self::$fMarkAspectRatioDefault;
  66. }
  67. public function getSiteLogo()
  68. {
  69. return $this->getSiteLogoParam('logo');
  70. }
  71. public function getSiteLogoDark()
  72. {
  73. return $this->getSiteLogoParam('logo_dark');
  74. }
  75. public function getSiteLogoUrl($iFileId = 0, $bOriginal = true)
  76. {
  77. if(!$iFileId && !($iFileId = (int)$this->getSiteLogo()))
  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 getSiteLogoDarkUrl($iFileId = 0, $bOriginal = true)
  93. {
  94. if(!$iFileId && !($iFileId = (int)$this->getSiteLogoDark()))
  95. return false;
  96. return $this->getSiteLogoUrl($iFileId, $bOriginal);
  97. }
  98. public function getSiteMark()
  99. {
  100. return $this->getSiteLogoParam('mark');
  101. }
  102. public function getSiteMarkDark()
  103. {
  104. return $this->getSiteLogoParam('mark_dark');
  105. }
  106. public function getSiteMarkUrl($iFileId = 0, $bOriginal = true)
  107. {
  108. if(!$iFileId && !($iFileId = (int)$this->getSiteMark()))
  109. return false;
  110. return $this->getSiteLogoUrl($iFileId, $bOriginal);
  111. }
  112. public function getSiteMarkDarkUrl($iFileId = 0, $bOriginal = true)
  113. {
  114. if(!$iFileId && !($iFileId = (int)$this->getSiteMarkDark()))
  115. return false;
  116. return $this->getSiteLogoUrl($iFileId, $bOriginal);
  117. }
  118. public function getSiteLogoInfo($iFileId = 0)
  119. {
  120. if(!$iFileId && !($iFileId = (int)$this->getSiteLogo()))
  121. return false;
  122. return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFile($iFileId);
  123. }
  124. public function getSiteLogoDarkInfo($iFileId = 0)
  125. {
  126. if(!$iFileId && !($iFileId = (int)$this->getSiteLogoDark()))
  127. return false;
  128. return $this->getSiteLogoInfo($iFileId);
  129. }
  130. public function getSiteMarkInfo($iFileId = 0)
  131. {
  132. if(!$iFileId && !($iFileId = (int)$this->getSiteMark()))
  133. return false;
  134. return $this->getSiteLogoInfo($iFileId);
  135. }
  136. public function getSiteMarkDarkInfo($iFileId = 0)
  137. {
  138. if(!$iFileId && !($iFileId = (int)$this->getSiteMarkDark()))
  139. return false;
  140. return $this->getSiteLogoInfo($iFileId);
  141. }
  142. public function getSiteLogoAlt()
  143. {
  144. return $this->getSiteLogoParam('logo_alt');
  145. }
  146. public function getSiteLogoWidth()
  147. {
  148. return ($iResult = $this->getSiteLogoValue('logo_width')) !== false ? $iResult : 0;
  149. }
  150. public function getSiteLogoDarkWidth()
  151. {
  152. return ($iResult = $this->getSiteLogoValue('logo_dark_width')) !== false ? $iResult : 0;
  153. }
  154. public function getSiteLogoHeight()
  155. {
  156. return ($iResult = $this->getSiteLogoValue('logo_height')) !== false ? $iResult : 0;
  157. }
  158. public function getSiteLogoDarkHeight()
  159. {
  160. return ($iResult = $this->getSiteLogoValue('logo_dark_height')) !== false ? $iResult : 0;
  161. }
  162. public function getSiteMarkWidth()
  163. {
  164. return ($iResult = $this->getSiteLogoValue('mark_width')) !== false ? $iResult : 0;
  165. }
  166. public function getSiteMarkDarkWidth()
  167. {
  168. return ($iResult = $this->getSiteLogoValue('mark_dark_width')) !== false ? $iResult : 0;
  169. }
  170. public function getSiteMarkHeight()
  171. {
  172. return ($iResult = $this->getSiteLogoValue('mark_height')) !== false ? $iResult : 0;
  173. }
  174. public function getSiteMarkDarkHeight()
  175. {
  176. return ($iResult = $this->getSiteLogoValue('mark_dark_height')) !== false ? $iResult : 0;
  177. }
  178. public function getSiteLogoParam($sName, $bGetSystem = false)
  179. {
  180. if(!empty($this->aParams[$sName]) && !$bGetSystem) {
  181. $sResult = getParam($this->aParams[$sName]);
  182. if(!empty($sResult))
  183. return $sResult;
  184. }
  185. return getParam('sys_site_' . $sName);
  186. }
  187. protected function getSiteLogoValue($sName)
  188. {
  189. return isset($this->aValues[$sName]) ? $this->aValues[$sName] : false;
  190. }
  191. }
  192. /** @} */