From e08ea4e14fc24160ffa57cd4477236989f310318 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Tue, 4 Feb 2014 00:56:50 +0100 Subject: [PATCH] Improved template pathes management: no more \ and / mix --- .../Core/Template/Assets/AsseticAssetManager.php | 11 ++++++++--- .../Smarty/Assets/SmartyAssetsManager.php | 6 ++++++ .../Thelia/Core/Template/TemplateDefinition.php | 16 ++++++++-------- core/lib/Thelia/Core/Template/TemplateHelper.php | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php index bca1ce1c7..e50a7a330 100644 --- a/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php +++ b/core/lib/Thelia/Core/Template/Assets/AsseticAssetManager.php @@ -316,8 +316,6 @@ class AsseticAssetManager implements AssetManagerInterface // Get the URL part from the relative path $outputRelativePath = $webAssetsTemplate . DS . $webAssetsKey; - $outputRelativeWebPath = rtrim(str_replace('\\', '/', $outputRelativePath), '/') . '/'; - $assetTargetFilename = $asset->getTargetPath(); /* @@ -333,11 +331,18 @@ class AsseticAssetManager implements AssetManagerInterface $writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory); - Tlog::getInstance()->addDebug("Writing asset to $outputDirectory . DS . $assetFileDirectoryInAssetDirectory"); + Tlog::getInstance()->addDebug("Writing asset to $outputDirectory" . DS . "$assetFileDirectoryInAssetDirectory"); $writer->writeAsset($asset); } + // Normalize path to generate a valid URL + if (DS != '/') { + $outputRelativeWebPath = str_replace(DS, '/', $outputRelativePath); + $assetFileDirectoryInAssetDirectory = str_replace(DS, '/', $assetFileDirectoryInAssetDirectory); + $assetTargetFilename = str_replace(DS, '/', $assetTargetFilename); + } + return rtrim($outputUrl, '/') . '/' . trim($outputRelativeWebPath, '/') . '/' . trim($assetFileDirectoryInAssetDirectory, '/') . '/' . ltrim($assetTargetFilename, '/'); } } diff --git a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php index 46440cc52..d595fdbe4 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php +++ b/core/lib/Thelia/Core/Template/Smarty/Assets/SmartyAssetsManager.php @@ -24,6 +24,7 @@ namespace Thelia\Core\Template\Smarty\Assets; +use Thelia\Log\Tlog; use Thelia\Tools\URL; use Thelia\Core\Template\Assets\AssetManagerInterface; @@ -109,6 +110,11 @@ class SmartyAssetsManager $assetSource = $templateDirectories[$templateDefinition->getName()][$assetOrigin]; + if (DS != '/') { + // Just to be sure to generate a clean pathname + $file = str_replace('/', DS, $file); + } + $url = $this->assetsManager->processAsset( $assetSource . DS . $file, $assetSource . DS . self::$assetsDirectory, diff --git a/core/lib/Thelia/Core/Template/TemplateDefinition.php b/core/lib/Thelia/Core/Template/TemplateDefinition.php index 28ac17866..b511414a5 100644 --- a/core/lib/Thelia/Core/Template/TemplateDefinition.php +++ b/core/lib/Thelia/Core/Template/TemplateDefinition.php @@ -30,10 +30,10 @@ class TemplateDefinition const PDF = 3; const EMAIL = 4; - const FRONT_OFFICE_SUBDIR = 'frontOffice/'; - const BACK_OFFICE_SUBDIR = 'backOffice/'; - const PDF_SUBDIR = 'pdf/'; - const EMAIL_SUBDIR = 'email/'; + const FRONT_OFFICE_SUBDIR = 'frontOffice'; + const BACK_OFFICE_SUBDIR = 'backOffice'; + const PDF_SUBDIR = 'pdf'; + const EMAIL_SUBDIR = 'email'; protected static $standardTemplatesSubdirs = array( self::FRONT_OFFICE => self::FRONT_OFFICE_SUBDIR, @@ -64,16 +64,16 @@ class TemplateDefinition switch ($type) { case TemplateDefinition::FRONT_OFFICE: - $this->path = self::FRONT_OFFICE_SUBDIR . $name; + $this->path = self::FRONT_OFFICE_SUBDIR . DS . $name; break; case TemplateDefinition::BACK_OFFICE: - $this->path = self::BACK_OFFICE_SUBDIR . $name; + $this->path = self::BACK_OFFICE_SUBDIR . DS . $name; break; case TemplateDefinition::PDF: - $this->path = self::PDF_SUBDIR . $name; + $this->path = self::PDF_SUBDIR . DS . $name; break; case TemplateDefinition::EMAIL: - $this->path = self::EMAIL_SUBDIR . $name; + $this->path = self::EMAIL_SUBDIR . DS . $name; break; default: $this->path = $name; diff --git a/core/lib/Thelia/Core/Template/TemplateHelper.php b/core/lib/Thelia/Core/Template/TemplateHelper.php index a95d7b899..c08d94c0a 100644 --- a/core/lib/Thelia/Core/Template/TemplateHelper.php +++ b/core/lib/Thelia/Core/Template/TemplateHelper.php @@ -129,7 +129,7 @@ class TemplateHelper if ($file->isDot() || ! $file->isDir()) continue; // Ignore reserved directory names - if (in_array($file->getFilename()."/", $exclude)) continue; + if (in_array($file->getFilename(), $exclude)) continue; $list[] = new TemplateDefinition($file->getFilename(), $templateType); }