瀏覽代碼

Ticket #3877 - Logo displaying improvement: Core changes.

AntonLV 4 年之前
父節點
當前提交
3c2069c2cf

+ 60 - 6
inc/classes/BxDolDesigns.php

@@ -9,10 +9,16 @@
 
 class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
 {
+    public static $fLogoAspectRatioDefault = 1.0;
+
     protected $sDesign;
     protected $oDesign;
 
     protected $aParams;
+    protected $aValues;
+
+    protected $sLogoStorage;
+    protected $sLogoTranscoder;
 
     protected function __construct()
     {
@@ -20,6 +26,9 @@ class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
             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';
     }
 
     /**
@@ -53,13 +62,18 @@ class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
             $this->oDesign = BxDolModule::getInstance($aDesign['name']);
 
     	//--- Init site's logo params.
-    	if($this->oDesign instanceof BxDolModule && method_exists($this->oDesign->_oConfig, 'getLogoParams'))
+    	if($this->oDesign instanceof BxDolModule && method_exists($this->oDesign->_oConfig, 'getLogoParams')) {
             list(
                 $this->aParams['logo'], 
-                $this->aParams['logo_alt'], 
-                $this->aParams['logo_width'], 
-                $this->aParams['logo_height']
+                $this->aParams['logo_alt']
             ) = $this->oDesign->_oConfig->getLogoParams();
+
+            list(
+                $this->aValues['logo_width'], 
+                $this->aValues['logo_height'],
+                $this->aValues['logo_aspect_ratio']
+            ) = $this->oDesign->_oConfig->getLogoValues($this->getSiteLogoUrl(), $this->getSiteLogoInfo());
+        }
     }
 
     public function getSiteLogo()
@@ -67,6 +81,41 @@ class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
     	return $this->getSiteLogoParam('logo');
     }
 
+    public function getSiteLogoUrl($iFileId = 0, $bOriginal = true)
+    {
+        if(!$iFileId)
+            $iFileId = (int)$this->getSiteLogo();
+        if(!$iFileId) 
+            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 getSiteLogoInfo($iFileId = 0)
+    {
+        if(!$iFileId)
+            $iFileId = (int)$this->getSiteLogo();
+        if(!$iFileId) 
+            return false;
+
+        return BxDolStorage::getObjectInstance($this->sLogoStorage)->getFile($iFileId);
+    }
+
     public function getSiteLogoAlt()
     {
     	return $this->getSiteLogoParam('logo_alt');
@@ -74,12 +123,12 @@ class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
 
     public function getSiteLogoWidth()
     {
-    	return $this->getSiteLogoParam('logo_width', !$this->oDesign->_oConfig->getLogo());
+    	return ($iResult = $this->getSiteLogoValue('logo_width')) !== false ? $iResult : 0;
     }
 
     public function getSiteLogoHeight()
     {
-    	return $this->getSiteLogoParam('logo_height', !$this->oDesign->_oConfig->getLogo());
+        return ($iResult = $this->getSiteLogoValue('logo_height')) !== false ? $iResult : 0;
     }
 
     protected function getSiteLogoParam($sName, $bGetSystem = false)
@@ -92,6 +141,11 @@ class BxDolDesigns extends BxDolFactory implements iBxDolSingleton
 
     	return getParam('sys_site_' . $sName);
     }
+
+    protected function getSiteLogoValue($sName)
+    {
+        return isset($this->aValues[$sName]) ? $this->aValues[$sName] : false;
+    }
 }
 
 /** @} */

+ 26 - 0
inc/utils.inc.php

@@ -507,6 +507,32 @@ function bx_get_image_exif_and_size($oStorage, $oTranscoder, $iContentId){
     return array('exif' => $sExif, 'size' => $sData);
 }
 
+function bx_get_svg_image_size($sUrl)
+{
+    $iWidth = $iHeight = 0;
+
+    $sContent = bx_file_get_contents($sUrl);
+    if(empty($sContent))
+        return [$iWidth, $iHeight];
+
+    $aAttributes = BxDolXmlParser::getInstance()->getAttributes($sContent, 'SVG', 0);
+    if(isset($aAttributes['VIEWBOX'])) {
+        $aViewBox = explode(' ', $aAttributes['VIEWBOX']);
+        if(!empty($aViewBox) && is_array($aViewBox) && count($aViewBox) == 4) {
+            $iWidth = (float)$aViewBox[2];
+            $iHeight = (float)$aViewBox[3];
+        }
+    }
+
+    if(!$iWidth && isset($aAttributes['WIDTH']))
+        $iWidth = $this->_str2px($aAttributes['WIDTH']);
+
+    if(!$iHeight && isset($aAttributes['HEIGHT']))
+        $iHeight = $this->_str2px($aAttributes['HEIGHT']);
+
+    return [$iWidth, $iHeight];
+}
+
 function extFileExists( $sFileSrc )
 {
     return (file_exists( $sFileSrc ) && is_file( $sFileSrc )) ? true : false;

File diff suppressed because it is too large
+ 3 - 2
install/sql/system.sql


+ 1 - 2
modules/boonex/english/data/langs/system/en.xml

@@ -1627,8 +1627,7 @@
 	<string name="_adm_stg_cpt_option_sys_security_impact_threshold_block"><![CDATA[Total security impact threshold to send report and block aggressor]]></string>
 	<string name="_adm_stg_cpt_option_sys_security_impact_threshold_log"><![CDATA[Total security impact threshold to send report]]></string>
         <string name="_adm_stg_cpt_option_sys_security_block_content_after_n_reports"><![CDATA[Block content after N reports (0 - do not block)]]></string>
-        <string name="_adm_stg_cpt_option_sys_site_logo_height"><![CDATA[Logo Height]]></string>
-	<string name="_adm_stg_cpt_option_sys_site_logo_width"><![CDATA[Logo Width]]></string>
+        <string name="_adm_stg_cpt_option_sys_site_logo_aspect_ratio"><![CDATA[Logo aspect ratio]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_default"><![CDATA[Default storage engine (other than Local may require custom/additional setup)]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_s3_access_key"><![CDATA[AWS access key]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_s3_bucket"><![CDATA[AWS bucket]]></string>

+ 1 - 2
modules/boonex/russian/data/langs/system/ru.xml

@@ -1614,8 +1614,7 @@
 	<string name="_adm_stg_cpt_option_sys_security_impact_threshold_block"><![CDATA[Общий порог угрозы бесопасности перед тем, как послать отчёт и заблокировать агрессора]]></string>
 	<string name="_adm_stg_cpt_option_sys_security_impact_threshold_log"><![CDATA[Общий порог угрозы бесопасности перед тем, как послать отчёт]]></string>
         <string name="_adm_stg_cpt_option_sys_security_block_content_after_n_reports"><![CDATA[Блокировать контент после N жалоб (0 - не блокировать)]]></string>
-	<string name="_adm_stg_cpt_option_sys_site_logo_height"><![CDATA[Высота лого]]></string>
-	<string name="_adm_stg_cpt_option_sys_site_logo_width"><![CDATA[Ширина лого]]></string>
+	<string name="_adm_stg_cpt_option_sys_site_logo_aspect_ratio"><![CDATA[Соотношение сторон лого]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_default"><![CDATA[Основной движок хранения (отличный от Local может потребовать дополнительную настройку)]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_s3_access_key"><![CDATA[AWS - ключ доступа]]></string>
 	<string name="_adm_stg_cpt_option_sys_storage_s3_bucket"><![CDATA[AWS - сегмент (bucket)]]></string>

+ 15 - 7
studio/classes/BxDolStudioDesigner.php

@@ -26,8 +26,6 @@ class BxDolStudioDesigner extends BxTemplStudioWidget
 
     protected $sParamLogo;
     protected $sParamLogoAlt;
-    protected $sParamLogoWidth;
-    protected $sParamLogoHeight;
 
     protected $aCovers;
 
@@ -46,8 +44,6 @@ class BxDolStudioDesigner extends BxTemplStudioWidget
 
         $this->sParamLogo = 'sys_site_logo';
         $this->sParamLogoAlt = 'sys_site_logo_alt';
-        $this->sParamLogoWidth = 'sys_site_logo_width';
-        $this->sParamLogoHeight = 'sys_site_logo_height';
 
         $this->aCovers = array(
             'cover_common' => array(
@@ -120,7 +116,7 @@ class BxDolStudioDesigner extends BxTemplStudioWidget
 
     function setLogoParams($aParams)
     {
-        list($this->sParamLogo, $this->sParamLogoAlt, $this->sParamLogoWidth, $this->sParamLogoHeight) = $aParams;
+        list($this->sParamLogo, $this->sParamLogoAlt) = $aParams;
     }
 
     function makeDefault()
@@ -136,6 +132,7 @@ class BxDolStudioDesigner extends BxTemplStudioWidget
     function submitLogo(&$oForm)
     {
         $iProfileId = getLoggedId();
+        $iValuePrior = $this->oDb->getParam($this->sParamLogo);
 
         if(!empty($_FILES['image']['tmp_name'])) {
             $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
@@ -151,11 +148,15 @@ class BxDolStudioDesigner extends BxTemplStudioWidget
 
             $this->oDb->setParam($this->sParamLogo, $iId);
             $oStorage->afterUploadCleanup($iId, $iProfileId);
+
+            bx_alert('system', 'change_logo', 0, 0, [
+                'option' => $this->sParamLogo, 
+                'value' => $iId,
+                'value_prior' => $iValuePrior
+            ]);
         }
 
         $this->oDb->setParam($this->sParamLogoAlt, $oForm->getCleanValue('alt'));
-        $this->oDb->setParam($this->sParamLogoWidth, $oForm->getCleanValue('width'));
-        $this->oDb->setParam($this->sParamLogoHeight, $oForm->getCleanValue('height'));
         return $this->getJsResult('_adm_dsg_scs_save', true, true, bx_append_url_params($this->sManageUrl, array('page' => BX_DOL_STUDIO_DSG_TYPE_LOGO)));
     }
 
@@ -170,6 +171,13 @@ class BxDolStudioDesigner extends BxTemplStudioWidget
             return false;
 
         $this->oDb->setParam($this->sParamLogo, 0);
+
+        bx_alert('system', 'change_logo', 0, 0, [
+            'option' => $this->sParamLogo, 
+            'value' => 0,
+            'value_prior' => $iId
+        ]);
+
         return true;
     }
 

+ 1 - 1
studio/template/form_view_iu_preview.html

@@ -7,7 +7,7 @@
     <div class="bx-form-input-preview">
         <img src="__url__" />
         <bx_if:show_action_delete>
-            <p>
+            <p class="bx-def-padding-thd-top">
                 <button type="button" class="bx-btn bx-btn-small" onclick="javascript:__action__">
                     <bx_text:_adm_txt_form_view_iu_delete />
                 </button>

+ 0 - 21
studio/template/scripts/BxBaseStudioDesigner.php

@@ -163,29 +163,8 @@ class BxBaseStudioDesigner extends BxDolStudioDesigner
                     'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
                     'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
                     'storage_object' => 'sys_images_custom',
-                    'transcoder_object' => 'sys_custom_images',
-                    'transcoder_image_width' => (int)getParam($this->sParamLogoWidth),
-                    'transcoder_image_height' => (int)getParam($this->sParamLogoHeight),
                     'value' => (int)getParam($this->sParamLogo),
                 ),
-                'width' => array(
-                    'type' => 'text',
-                    'name' => 'width',
-                    'caption' => _t('_adm_stg_cpt_option_sys_site_logo_width'),
-                    'value' => (int)getParam($this->sParamLogoWidth),
-                    'db' => array (
-                        'pass' => 'Int',
-                    ),
-                ),
-                'height' => array(
-                    'type' => 'text',
-                    'name' => 'height',
-                    'caption' => _t('_adm_stg_cpt_option_sys_site_logo_height'),
-                    'value' => (int)getParam($this->sParamLogoHeight),
-                    'db' => array (
-                        'pass' => 'Int',
-                    ),
-                ),
                 'alt' => array(
                     'type' => 'text',
                     'name' => 'alt',

+ 4 - 22
template/scripts/BxBaseFunctions.php

@@ -524,25 +524,7 @@ class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
      */
     function getMainLogoUrl()
     {
-        $oDesigns = BxDolDesigns::getInstance();
-
-        $iFileId = (int)$oDesigns->getSiteLogo();
-        if(!$iFileId) 
-            return false;
-
-        $aParams = array();
-        if(($iLogoWidth = (int)$oDesigns->getSiteLogoWidth()) > 0)
-            $aParams['x'] = $iLogoWidth;
-
-        if(($iLogoHeight = (int)$oDesigns->getSiteLogoHeight()) > 0)
-            $aParams['y'] = $iLogoHeight;
-
-        if(!empty($aParams))
-            $sFileUrl = BX_DOL_URL_ROOT . bx_append_url_params('image_transcoder.php', array_merge(array('o' => 'sys_custom_images', 'h' => $iFileId), $aParams));
-        else 
-            $sFileUrl = BxDolTranscoder::getObjectInstance('sys_custom_images')->getFileUrl($iFileId);
-
-        return !empty($sFileUrl) ? $sFileUrl : false;
+        return BxDolDesigns::getInstance()->getSiteLogoUrl();
     }
 
     /**
@@ -562,12 +544,12 @@ class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
         $sFileUrl = $this->getMainLogoUrl();
         if (!empty($sFileUrl)) {
             $iLogoWidth = (int)$oDesigns->getSiteLogoWidth();
-            $sMaxWidth = $iLogoWidth > 0 ? 'max-width:' . round($iLogoWidth/16, 3) . 'rem;' : '';
+            $sWidth = $iLogoWidth > 0 ? 'width:' . round($iLogoWidth/16, 3) . 'rem;' : '';
 
             $iLogoHeight = (int)$oDesigns->getSiteLogoHeight();
-            $sMaxHeight = $iLogoHeight > 0 ? 'max-height:' . round($iLogoHeight/16, 3) . 'rem;' : '';
+            $sHeight = $iLogoHeight > 0 ? 'height:' . round($iLogoHeight/16, 3) . 'rem;' : '';
 
-            $sLogo = '<img style="' . $sMaxWidth . $sMaxHeight . '" src="' . $sFileUrl . '" id="bx-logo" alt="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '" />';
+            $sLogo = '<img style="' . $sWidth . ' ' . $sHeight . '" src="' . $sFileUrl . '" id="bx-logo" alt="' . bx_html_attribute($sAlt, BX_ESCAPE_STR_QUOTE) . '" />';
         }
 
         $aAttrs = array(

Some files were not shown because too many files changed in this diff