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

Ticket #3398 - Possibility to overwrite CSS files from Base modules.

AntonLV 5 лет назад
Родитель
Сommit
17fa7477d6
2 измененных файлов с 64 добавлено и 32 удалено
  1. 35 23
      inc/classes/BxDolModuleTemplate.php
  2. 29 9
      inc/classes/BxDolTemplate.php

+ 35 - 23
inc/classes/BxDolModuleTemplate.php

@@ -55,18 +55,26 @@ class BxDolModuleTemplate extends BxDolTemplate
         $this->_oTemplateFunctions = BxTemplFunctions::getInstance($this);
     }
 
-    public function addLocationBase()
-    {        
-    }
+    public function addLocationBase() {}
 
     function addCssSystem($mixedFiles, $bDynamic = false)
     {
-        return $this->_addFiles(BxDolTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
+        $bResult = false;
+
+        foreach($this->getLocations() as $sKey => $aLocation)
+            $bResult |= $this->_addFiles(BxDolTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true, [$sKey => $aLocation]);
+
+        return $bResult;
     }
 
     function addCss($mixedFiles, $bDynamic = false)
     {
-        return $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true);
+        $bResult = false;
+
+        foreach($this->getLocations() as $sKey => $aLocation)
+            $bResult |= $this->_addFiles(BxDolTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, true, [$sKey => $aLocation]);
+
+        return $bResult;
     }
 
     function addJsSystem($mixedFiles, $bDynamic = false)
@@ -89,12 +97,12 @@ class BxDolModuleTemplate extends BxDolTemplate
         return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCss', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
     }
 
-	function addStudioCssSystem($mixedFiles, $bDynamic = false, $bSearchInModule = true)
+    function addStudioCssSystem($mixedFiles, $bDynamic = false, $bSearchInModule = true)
     {
         return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addCssSystem', 'isLocation', 'addLocation', 'removeLocation', '', $mixedFiles, $bDynamic, $bSearchInModule);
     }
 
-	function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
+    function addStudioJs($mixedFiles, $bDynamic = false, $bSearchInModule = true)
     {
         return $this->_addFiles(BxDolStudioTemplate::getInstance(), 'addJs', 'isLocationJs', 'addLocationJs', 'removeLocationJs', 'js/', $mixedFiles, $bDynamic, $bSearchInModule);
     }
@@ -109,29 +117,33 @@ class BxDolModuleTemplate extends BxDolTemplate
         BxDolStudioTemplate::getInstance()->addJsTranslation($mixedKey);
     }
 
-    function _addFiles($oTemplate, $sFuncAddFiles, $sFuncIsLocation, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true)
+    function _addFiles($oTemplate, $sFuncAddFiles, $sFuncIsLocation, $sFuncAddLocation, $sFuncRemoveLocation, $sPath, $mixedFiles, $bDynamic = false, $bSearchInModule = true, $aLocations = array())
     {
-        $sLocationKey = '';
-        $bLocationRemove = false;
-
         if($bSearchInModule) {
-            if(strpos($sFuncAddLocation, 'Dynamic') === false) {
-                $sLocationKey = $this->_oConfig->getName();
-                if(!$oTemplate->$sFuncIsLocation($sLocationKey)) {
-                    $sLocationKey = $oTemplate->$sFuncAddLocation($sLocationKey, $this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
-                    $bLocationRemove = true;
-                }
-            }
-            else {
-                $sLocationKey = $oTemplate->$sFuncAddLocation($this->_oConfig->getHomePath() . $sPath, $this->_oConfig->getHomeUrl() . $sPath);
-                $bLocationRemove = true;
+            if(empty($aLocations))
+                $aLocations = [
+                    $this->_oConfig->getName() => [
+                        'path' => $this->_oConfig->getHomePath() . $sPath,
+                        'url' => $this->_oConfig->getHomeUrl() . $sPath
+                    ]
+                ];
+
+            foreach($aLocations as $sLocationKey => $aLocation) {
+                if($oTemplate->$sFuncIsLocation($sLocationKey))
+                    continue;
+
+                $oTemplate->$sFuncAddLocation($sLocationKey, $aLocation['path'], $aLocation['url']);
+                
+                $aLocations[$sLocationKey]['delete'] = true;
             }
         }
 
         $mixedResult = $oTemplate->$sFuncAddFiles($mixedFiles, $bDynamic);
 
-        if($bLocationRemove && $sLocationKey != '')
-            $oTemplate->$sFuncRemoveLocation($sLocationKey);
+        if($bSearchInModule && !empty($aLocations))
+            foreach($aLocations as $sLocationKey => $aLocation) 
+                if(isset($aLocation['delete']) && $aLocation['delete'] === true)
+                    $oTemplate->$sFuncRemoveLocation($sLocationKey);           
 
         return $mixedResult;
     }

+ 29 - 9
inc/classes/BxDolTemplate.php

@@ -885,6 +885,15 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         return isset($this->_aLocations[$sKey]);
     }
 
+    /**
+     * Get a lis of all added locations.
+     * @return array with locations.
+     */
+    function getLocations()
+    {
+        return $this->_aLocations;
+    }
+
     /**
      * Add location in array of locations.
      * Note. Location is the path/url to folder where 'templates' folder is stored.
@@ -2747,15 +2756,26 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
 
         $sResult = '';
         $aLocations = array_reverse($this->_aLocations, true);
-        foreach($aLocations as $sKey => $aLocation) {
-            if((in_array($sCheckIn, array(BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_TMPL)) || (isset($sCheckIn['in'], $sCheckIn['sub']) && in_array($sCheckIn['in'], array(BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_TMPL)) && $sCheckIn['sub'] == $sKey)) && extFileExists(BX_DIRECTORY_PATH_MODULES . $this->getPath(). 'data' . DIRECTORY_SEPARATOR . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sKey . DIRECTORY_SEPARATOR . $sFolder . $sName))
-                $sResult = $sRoot . 'modules' . $sDivider . $sDirectory. 'data' . $sDivider . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sKey . $sDivider . $sFolder . $sName;
-            else if((in_array($sCheckIn, array(BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_BASE)) || (isset($sCheckIn['in'], $sCheckIn['sub']) && in_array($sCheckIn['in'], array(BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_BASE)) && $sCheckIn['sub'] == $sKey)) && extFileExists($aLocation['path'] . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sFolder . $sName))
-                $sResult = $aLocation[$sType] . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sFolder . $sName;
-            else
-                continue;
-            break;
-        }
+
+        //--- Check it Template.
+        $bInSub = false;
+        $aCheckIn = [BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_TMPL];
+        if(in_array($sCheckIn, $aCheckIn) || $bInSub = (isset($sCheckIn['in'], $sCheckIn['sub']) && in_array($sCheckIn['in'], $aCheckIn)))
+            foreach($aLocations as $sKey => $aLocation)
+                if((!$bInSub || $sCheckIn['sub'] == $sKey) && extFileExists(BX_DIRECTORY_PATH_MODULES . $this->getPath(). 'data' . DIRECTORY_SEPARATOR . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sKey . DIRECTORY_SEPARATOR . $sFolder . $sName)) {
+                    $sResult = $sRoot . 'modules' . $sDivider . $sDirectory. 'data' . $sDivider . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sKey . $sDivider . $sFolder . $sName;
+                    break;
+                }
+
+        //--- Check it Base.
+        $bInSub = false;
+        $aCheckIn = [BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_BASE];
+        if(empty($sResult) && (in_array($sCheckIn, $aCheckIn) || $bInSub = (isset($sCheckIn['in'], $sCheckIn['sub']) && in_array($sCheckIn['in'], $aCheckIn))))
+            foreach($aLocations as $sKey => $aLocation)
+                if((!$bInSub || $sCheckIn['sub'] == $sKey) && extFileExists($aLocation['path'] . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sFolder . $sName)) {
+                    $sResult = $aLocation[$sType] . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sFolder . $sName;
+                    break;
+                }
 
         /**
          * try to find from received path