diff --git a/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php b/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php index dbeec3759..205ce59ee 100644 --- a/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php +++ b/core/lib/Thelia/Core/Template/Assets/AssetManagerInterface.php @@ -43,6 +43,7 @@ interface AssetManagerInterface { * Generates assets from $asset_path in $output_path, using $filters. * * @param $assetSource + * @param $assetDirectoryBase * @param $webAssetsDirectoryBase * @param $webAssetsTemplate * @param $webAssetsKey @@ -60,5 +61,5 @@ interface AssetManagerInterface { * @internal param string $asset_type the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension. * @return string The URL to the generated asset file. */ - public function processAsset($assetSource, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug); + public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug); } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php index f3c2dad09..8df9de584 100755 --- a/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php @@ -273,6 +273,7 @@ class AsseticAssetManager implements AssetManagerInterface * Generates assets from $asset_path in $output_path, using $filters. * * @param $assetSource + * @param $assetDirectoryBase * @param string $webAssetsDirectoryBase the full path to the asset file (or file collection, e.g. *.less) * * @param string $webAssetsTemplate the full disk path to the base assets output directory in the web space @@ -286,11 +287,13 @@ class AsseticAssetManager implements AssetManagerInterface * * @return string The URL to the generated asset file. */ - public function processAsset($assetSource, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug) + public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug) { $assetName = basename($assetSource); $inputDirectory = realpath(dirname($assetSource)); + $assetFileDirectoryInAssetDirectory = trim(str_replace(array($assetDirectoryBase, $assetName), '', $assetSource), DS); + $am = new AssetManager(); $fm = new FilterManager(); @@ -318,21 +321,24 @@ class AsseticAssetManager implements AssetManagerInterface $assetTargetFilename = $asset->getTargetPath(); - // This is the final name of the generated asset - $assetDestinationPath = $outputDirectory . DS . $assetTargetFilename; + /* + * This is the final name of the generated asset + * We preserve file structure intending to keep - for example - relative css links working + */ + $assetDestinationPath = $outputDirectory . DS . $assetFileDirectoryInAssetDirectory . DS . $assetTargetFilename; Tlog::getInstance()->addDebug("Asset destination full path: $assetDestinationPath"); // We generate an asset only if it does not exists, or if the asset processing is forced in development mode if (! file_exists($assetDestinationPath) || ($this->debugMode && ConfigQuery::read('process_assets', true)) ) { - $writer = new AssetWriter($outputDirectory); + $writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory); - Tlog::getInstance()->addDebug("Writing asset to $outputDirectory"); + Tlog::getInstance()->addDebug("Writing asset to $outputDirectory . DS . $assetFileDirectoryInAssetDirectory"); $writer->writeAsset($asset); } - return rtrim($outputUrl, '/') . '/' . $outputRelativeWebPath . $assetTargetFilename; + return rtrim($outputUrl, DS) . DS . trim($outputRelativeWebPath, DS) . DS . trim($assetFileDirectoryInAssetDirectory, DS) . DS . ltrim($assetTargetFilename, DS); } } \ No newline at end of file diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 961b480db..3600f3d61 100755 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -37,6 +37,8 @@ class SmartyAssetsManager private $web_root; private $path_relative_to_web_root; + static private $assetsDirectory = null; + /** * Creates a new SmartyAssetsManager instance * @@ -54,6 +56,7 @@ class SmartyAssetsManager public function prepareAssets($assets_directory, \Smarty_Internal_Template $template) { + self::$assetsDirectory = $assets_directory; $smartyParser = $template->smarty; $templateDefinition = $smartyParser->getTemplateDefinition(); switch($templateDefinition->getType()) { @@ -62,7 +65,7 @@ class SmartyAssetsManager if(isset($frontOfficeTemplateDirectories[$templateDefinition->getName()])) { /* create assets foreach directory : main @ modules */ foreach($frontOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) { - $tpl_path = $directory . DS . $assets_directory; + $tpl_path = $directory . DS . self::$assetsDirectory; $asset_dir_absolute_path = realpath($tpl_path); if(false !== $asset_dir_absolute_path) { $this->assetsManager->prepareAssets( @@ -81,7 +84,7 @@ class SmartyAssetsManager if(isset($backOfficeTemplateDirectories[$templateDefinition->getName()])) { /* create assets foreach directory : main @ modules */ foreach($backOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) { - $tpl_path = $directory . DS . $assets_directory; + $tpl_path = $directory . DS . self::$assetsDirectory; $asset_dir_absolute_path = realpath($tpl_path); if(false !== $asset_dir_absolute_path) { $this->assetsManager->prepareAssets( @@ -104,7 +107,7 @@ class SmartyAssetsManager // $tpl_dir = dirname($template->source->filepath); // -// $tpl_path = $tpl_dir . DS . $assets_directory; +// $tpl_path = $tpl_dir . DS . self::$assetsDirectory; // $asset_dir_absolute_path = realpath($tpl_path); // if ($asset_dir_absolute_path === false) { // /* no assets for current template */ @@ -176,6 +179,7 @@ class SmartyAssetsManager $url = $this->assetsManager->processAsset( $assetSource . DS . $file, + $assetSource . DS . self::$assetsDirectory, $this->web_root . $this->path_relative_to_web_root, $templateDefinition->getPath(), $assetOrigin,