| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaCore UNA Core
- * @{
- */
- class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
- {
- public static $fLogoAspectRatioDefault = 1.0;
- public static $fMarkAspectRatioDefault = 1.0;
- protected $sDesign;
- protected $oDesign;
- protected $aParams;
- protected $aValues;
- protected $sLogoStorage;
- protected $sLogoTranscoder;
- protected function __construct()
- {
- if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
- trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
- parent::__construct();
- $this->sLogoStorage = 'sys_images_custom';
- $this->sLogoTranscoder = 'sys_custom_images';
- }
- /**
- * Prevent cloning the instance
- */
- public function __clone()
- {
- if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
- trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
- }
- /**
- * Get singleton instance of the class
- */
- static function getInstance()
- {
- if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
- $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolDesigns();
- $GLOBALS['bxDolClasses'][__CLASS__]->init();
- }
- return $GLOBALS['bxDolClasses'][__CLASS__];
- }
- protected function init()
- {
- $this->sDesign = BxDolTemplate::getInstance()->getCode();
- $aDesign = BxDolModuleQuery::getInstance()->getModuleByUri($this->sDesign);
- if(!empty($aDesign) && is_array($aDesign))
- $this->oDesign = BxDolModule::getInstance($aDesign['name']);
- //--- Init site's logo params.
- if($this->oDesign instanceof BxDolModule && method_exists($this->oDesign->_oConfig, 'getLogoParams')) {
- $this->aParams = $this->oDesign->_oConfig->getLogoParams();
- $this->aValues = $this->oDesign->_oConfig->getLogoValues('logo', $this->getSiteLogoUrl(), $this->getSiteLogoInfo());
- if(isset($this->aParams['logo_dark']))
- $this->aValues += $this->oDesign->_oConfig->getLogoValues('logo_dark', $this->getSiteLogoDarkUrl(), $this->getSiteLogoDarkInfo());
- $this->aValues += $this->oDesign->_oConfig->getLogoValues('mark', $this->getSiteMarkUrl(), $this->getSiteMarkInfo());
- if(isset($this->aParams['mark_dark']))
- $this->aValues += $this->oDesign->_oConfig->getLogoValues('mark_dark', $this->getSiteMarkDarkUrl(), $this->getSiteMarkDarkInfo());
- }
- }
- public static function getAspectRatioDefault($sType)
- {
- return in_array($sType, ['logo', 'logo_dark']) ? self::$fLogoAspectRatioDefault : self::$fMarkAspectRatioDefault;
- }
- public function getSiteLogo()
- {
- return $this->getSiteLogoParam('logo');
- }
-
- public function getSiteLogoDark()
- {
- return $this->getSiteLogoParam('logo_dark');
- }
- public function getSiteLogoUrl($iFileId = 0, $bOriginal = true)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteLogo()))
- return false;
- if($bOriginal)
- return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFileUrlById($iFileId);
- $aParams = [];
- if(($iLogoWidth = (int)$this->getSiteLogoWidth()) > 0)
- $aParams['x'] = $iLogoWidth;
- if(($iLogoHeight = (int)$this->getSiteLogoHeight()) > 0)
- $aParams['y'] = $iLogoHeight;
- if(!empty($aParams))
- $sFileUrl = BX_DOL_URL_ROOT . bx_append_url_params('image_transcoder.php', array_merge(array('o' => $this->sLogoTranscoder, 'h' => $iFileId), $aParams));
- else
- $sFileUrl = BxDolTranscoder::getObjectInstance($this->sLogoTranscoder)->getFileUrl($iFileId);
- return !empty($sFileUrl) ? $sFileUrl : false;
- }
-
- public function getSiteLogoDarkUrl($iFileId = 0, $bOriginal = true)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteLogoDark()))
- return false;
- return $this->getSiteLogoUrl($iFileId, $bOriginal);
- }
- public function getSiteMark()
- {
- return $this->getSiteLogoParam('mark');
- }
- public function getSiteMarkDark()
- {
- return $this->getSiteLogoParam('mark_dark');
- }
- public function getSiteMarkUrl($iFileId = 0, $bOriginal = true)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteMark()))
- return false;
- return $this->getSiteLogoUrl($iFileId, $bOriginal);
- }
- public function getSiteMarkDarkUrl($iFileId = 0, $bOriginal = true)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteMarkDark()))
- return false;
- return $this->getSiteLogoUrl($iFileId, $bOriginal);
- }
- public function getSiteLogoInfo($iFileId = 0)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteLogo()))
- return false;
- return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFile($iFileId);
- }
- public function getSiteLogoDarkInfo($iFileId = 0)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteLogoDark()))
- return false;
- return $this->getSiteLogoInfo($iFileId);
- }
- public function getSiteMarkInfo($iFileId = 0)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteMark()))
- return false;
- return $this->getSiteLogoInfo($iFileId);
- }
- public function getSiteMarkDarkInfo($iFileId = 0)
- {
- if(!$iFileId && !($iFileId = (int)$this->getSiteMarkDark()))
- return false;
- return $this->getSiteLogoInfo($iFileId);
- }
- public function getSiteLogoAlt()
- {
- return $this->getSiteLogoParam('logo_alt');
- }
- public function getSiteLogoWidth()
- {
- return ($iResult = $this->getSiteLogoValue('logo_width')) !== false ? $iResult : 0;
- }
- public function getSiteLogoDarkWidth()
- {
- return ($iResult = $this->getSiteLogoValue('logo_dark_width')) !== false ? $iResult : 0;
- }
- public function getSiteLogoHeight()
- {
- return ($iResult = $this->getSiteLogoValue('logo_height')) !== false ? $iResult : 0;
- }
-
- public function getSiteLogoDarkHeight()
- {
- return ($iResult = $this->getSiteLogoValue('logo_dark_height')) !== false ? $iResult : 0;
- }
- public function getSiteMarkWidth()
- {
- return ($iResult = $this->getSiteLogoValue('mark_width')) !== false ? $iResult : 0;
- }
- public function getSiteMarkDarkWidth()
- {
- return ($iResult = $this->getSiteLogoValue('mark_dark_width')) !== false ? $iResult : 0;
- }
- public function getSiteMarkHeight()
- {
- return ($iResult = $this->getSiteLogoValue('mark_height')) !== false ? $iResult : 0;
- }
- public function getSiteMarkDarkHeight()
- {
- return ($iResult = $this->getSiteLogoValue('mark_dark_height')) !== false ? $iResult : 0;
- }
- public function getSiteLogoParam($sName, $bGetSystem = false)
- {
- if(!empty($this->aParams[$sName]) && !$bGetSystem) {
- $sResult = getParam($this->aParams[$sName]);
- if(!empty($sResult))
- return $sResult;
- }
- return getParam('sys_site_' . $sName);
- }
- protected function getSiteLogoValue($sName)
- {
- return isset($this->aValues[$sName]) ? $this->aValues[$sName] : false;
- }
- }
- /** @} */
|