Просмотр исходного кода

Ticket #3966 - Allow to overwrite layout icons/images: Usage in Artificer

AntonLV 4 лет назад
Родитель
Сommit
0e809cc531

+ 8 - 8
inc/classes/BxDolTemplate.php

@@ -676,15 +676,15 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
     protected function initImages()
     {
         self::$_iImagesCacheTTL = 86400;
-        self::$_sImagesCacheKey = $this->_sCacheFilePrefix . $this->_sCode .  '_' . bx_site_hash('images') . '.php';
+        self::$_sImagesCacheKey = 'db_layout_images_' . $this->_sCode .  '_' . bx_site_hash('images') . '.php';
         self::$_aImages = BxDolDb::getInstance()->getDbCacheObject()->getData(self::$_sImagesCacheKey);
         if(!self::$_aImages)
             self::$_aImages = [];
 
-        bx_alert('system', 'get_layout_images', 0, false, array(
+        bx_alert('system', 'get_layout_images', 0, false, [
             'code' => $this->_sCode,
             'override_result' => &self::$_aImages
-        ));
+        ]);
     }
 
     protected function saveImages()
@@ -1422,18 +1422,18 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         if(!isset(self::$_aImages[$sKey])) {
             $aResult = [
                 'v' => $sName,
-                'c' => $sClasses,
-                't' => 'ic'
+                't' => 'ic',
+                'c' => $sClasses
             ];
 
             $sUrl = '';
             foreach(['Image', 'Icon'] as $sType) 
-                foreach(['png', 'jpg', 'gif'] as $sExt)
+                foreach(['svg', 'png', 'jpg', 'gif'] as $sExt)
                     if(($sUrl = $this->{'get' . $sType . 'Url'}($sName . '.' . $sExt, $sCheckIn)) != '') {
                         $aResult = [
                             'v' => $sUrl,
-                            'c' => $sClasses,
-                            't' => 'im'
+                            't' => 'im',
+                            'c' => $sClasses
                         ];
                         break 2;
                     }

+ 60 - 1
modules/boonex/artificer/classes/BxArtificerAlertsResponse.php

@@ -12,7 +12,7 @@
 
 class BxArtificerAlertsResponse extends BxBaseModTemplateAlertsResponse
 {
-    function __construct()
+    public function __construct()
     {
         $this->_sModule = 'bx_artificer';
 
@@ -57,6 +57,65 @@ class BxArtificerAlertsResponse extends BxBaseModTemplateAlertsResponse
         }
     }
 
+    protected function _processSystemGetLayoutImages($oAlert)
+    {
+        $sImages = getParam($this->_oModule->_oConfig->getPrefix('option') . 'images_custom');
+        if(!$sImages)
+            return;
+        
+        $aImages = preg_split("/\\r\\n|\\r|\\n/", $sImages);
+        if(empty($aImages) || !is_array($aImages))
+            return;
+
+        foreach($aImages as $sImage) {
+            $aImage = explode('=>', $sImage);
+            if(empty($aImage))
+                continue;
+
+            switch(count($aImage)) {
+                case 2:
+                    list($sName, $sValue) = $aImage;
+
+                    $aCacheItemKeys = ['v'];
+                    $aCacheItemValues = [$sValue];
+                    break;
+
+                case 3:
+                    list($sName, $sValue, $sType) = $aImage;
+
+                    $aCacheItemKeys = ['v', 't'];
+                    $aCacheItemValues = [$sValue, $sType];
+                    break;
+
+                case 4:
+                    list($sName, $sValue, $sType, $sClass) = $aImage;
+
+                    $aCacheItemKeys = ['v', 't', 'c'];
+                    $aCacheItemValues = [$sValue, $sType, $sClass];
+                    break;
+
+                default:
+                    continue 2;
+            }
+
+            $sCacheItemKey = md5(trim($sName));
+            if(!isset($oAlert->aExtras['override_result'][$sCacheItemKey]))
+                continue;
+            
+            foreach($aCacheItemValues as $i => $s)
+                $aCacheItemValues[$i] = trim($s);
+
+            $aCacheItem = array_combine($aCacheItemKeys, $aCacheItemValues);
+
+            if(isset($aCacheItem['t']) && $aCacheItem['t'] == 'im')
+                foreach(['Image', 'Icon'] as $sUrlType) 
+                    if(($sUrl = $this->_oModule->_oTemplate->{'get' . $sUrlType . 'Url'}($aCacheItem['v'])) != '')
+                        $aCacheItem['v'] = $sUrl;
+
+            $oAlert->aExtras['override_result'][$sCacheItemKey] = array_merge($oAlert->aExtras['override_result'][$sCacheItemKey], $aCacheItem);
+        }
+    }
+
     protected function _processProfileUnit($oAlert)
     {
         if(!$this->_isActive())

+ 43 - 0
modules/boonex/artificer/classes/BxArtificerStudioOptions.php

@@ -0,0 +1,43 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Artificer Artificer template
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxArtificerStudioOptions extends BxTemplStudioOptions
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    public function __construct($sType = '', $sCategory = '', $sMix = '')
+    {
+        parent::__construct($sType, $sCategory, $sMix);
+
+        $this->_sModule = 'bx_artificer';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+    }
+
+    protected function field($aItem, $aItems2Mixes)
+    {
+        $sPrefix = $this->_oModule->_oConfig->getPrefix('option');
+
+        $aField = parent::field($aItem, $aItems2Mixes);
+
+        switch($aItem['name']) {
+            case $sPrefix . 'images_custom':
+                $aField = array_merge($aField, [
+                    'info' => _t('_bx_artificer_stg_cpt_option_images_custom_inf'),
+                    'code' => 1
+                ]);
+                break;
+        }
+
+        return $aField;
+    }
+}
+/** @} */

+ 4 - 2
modules/boonex/artificer/classes/BxArtificerStudioPage.php

@@ -9,6 +9,8 @@
  * @{
  */
 
+require_once('BxArtificerStudioOptions.php');
+
 define('BX_ARTIFICER_STUDIO_TEMPL_TYPE_STYLES', 'styles');
 
 class BxArtificerStudioPage extends BxTemplStudioDesign
@@ -36,14 +38,14 @@ class BxArtificerStudioPage extends BxTemplStudioDesign
                 $sPrefix . '_styles_custom',
             ];
 
-    	$oOptions = new BxTemplStudioOptions($this->sModule, $mixedCategory, $sMix);
+    	$oOptions = new BxArtificerStudioOptions($this->sModule, $mixedCategory, $sMix);
 
         $this->aPageCss = array_merge($this->aPageCss, $oOptions->getCss(), [BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css']);
         $this->aPageJs = array_merge($this->aPageJs, $oOptions->getJs(), ['codemirror/codemirror.min.js']);
         return BxDolStudioTemplate::getInstance()->parseHtmlByName('design.html', [
             'content' => $oOptions->getCode(),
             'js_content' => $this->getPageJsCode([
-                'sCodeMirror' => "textarea[name='" . $sPrefix . "_styles_custom']"
+                'sCodeMirror' => "textarea[name='" . $sPrefix . "_styles_custom'],textarea[name='" . $sPrefix . "_images_custom']"
             ])
         ]);
     }

+ 4 - 0
modules/boonex/artificer/data/template/system/css/general.css

@@ -26,6 +26,10 @@ import url(../../../../../../../template/css/general.css);
 .bx-toolbar-item.bx-ti-search .bx-ti-search-button a {
     text-decoration: none;
 }
+.bx-toolbar-item.bx-ti-search .bx-ti-search-button img {
+    width: 1.5rem;
+    height: 1.5rem;
+}
 .bx-toolbar-item.bx-ti-search .bx-tis-button-hidden {
     display: none;
 }

+ 1 - 1
modules/boonex/artificer/data/template/system/pt_application.html

@@ -38,7 +38,7 @@
                         <div class="bx-ti-search-button group relative inline-flex lg:hidden items-center mx-2 text-gray-600 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 text-base font-medium leading-6 border border-transparent hover:border-gray-200/50 active:border-gray-300 dark:hover:border-gray-700/50 dark:active:border-gray-700 bg-gray-100 dark:bg-gray-700/50 active:bg-gray-300 dark:active:bg-black/50 hover:bg-gray-200/50 dark:hover:bg-gray-700/50 rounded-full">
                             <a href="javascript:void(0)" onclick="javascript:bx_site_search_show(this)">
                                 <span class="relative flex items-center justify-center h-8 w-8 md:h-10 md:w-10">
-                                    <i class="sys-icon search"></i>
+                                    <bx_image_auto:search />
                                 </span>
                             </a>
                         </div>

+ 2 - 0
modules/boonex/artificer/install/langs/en.xml

@@ -12,6 +12,8 @@
 
     <string name="_bx_artificer_stg_cpt_category_styles_custom"><![CDATA[Custom Styles]]></string>
     <string name="_bx_artificer_stg_cpt_option_styles_custom"><![CDATA[Custom Styles]]></string>
+    <string name="_bx_artificer_stg_cpt_option_images_custom"><![CDATA[Custom Images]]></string>
+    <string name="_bx_artificer_stg_cpt_option_images_custom_inf"><![CDATA[Each line represents an image. Line format: <b>name</b> => <b>value</b> => <b>type</b> => <b>class</b><br />Where <b>type</b> and/or <b>class</b> may be omitted. Available types are <b>ic</b> - icon (Font Awesome), <b>im</b> - image (file name or URL), <b>sc</b> - source code (SVG).]]></string>
 
     <!-- Pages -->
     <string name="_bx_artificer_page_block_title_splash"><![CDATA[Splash]]></string>

+ 1 - 0
modules/boonex/artificer/install/sql/enable.sql

@@ -26,6 +26,7 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('system', 'change_logo', @iHandler),
 ('system', 'change_mark', @iHandler),
 ('system', 'get_object', @iHandler),
+('system', 'get_layout_images', @iHandler),
 ('profile', 'unit', @iHandler);
 
 

+ 2 - 1
modules/boonex/artificer/install/sql/install.sql

@@ -22,7 +22,8 @@ INSERT INTO `sys_options_categories`(`type_id`, `name`, `caption`, `order`) VALU
 SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
-(@iCategoryId, CONCAT(@sName, '_styles_custom'), '_bx_artificer_stg_cpt_option_styles_custom', '', 'text', '', '', '', 1);
+(@iCategoryId, CONCAT(@sName, '_styles_custom'), '_bx_artificer_stg_cpt_option_styles_custom', '', 'text', '', '', '', 1),
+(@iCategoryId, CONCAT(@sName, '_images_custom'), '_bx_artificer_stg_cpt_option_images_custom', '', 'text', '', '', '', 10);
 
 -- SETTINGS: Artificer template Site Logo
 SET @iSystemCategoryId = (SELECT IFNULL(`id`, @iCategoryId) FROM `sys_options_categories` WHERE `name`='system' LIMIT 1);