Skip to content

Commit

Permalink
Ticket #3398 - Possibility to overwrite CSS files from Base modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLV committed Sep 17, 2021
1 parent 9ab6b2f commit 17fa747
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 32 deletions.
58 changes: 35 additions & 23 deletions inc/classes/BxDolModuleTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,26 @@ public function init()
$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)
Expand All @@ -89,12 +97,12 @@ function addStudioCss($mixedFiles, $bDynamic = false, $bSearchInModule = true)
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);
}
Expand All @@ -109,29 +117,33 @@ function addStudioJsTranslation($mixedKey)
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;
}
Expand Down
38 changes: 29 additions & 9 deletions inc/classes/BxDolTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,15 @@ function isLocation($sKey)
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.
Expand Down Expand Up @@ -2747,15 +2756,26 @@ function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPL

$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
Expand Down

0 comments on commit 17fa747

Please sign in to comment.