Merge pull request #382 from bibich/improvements

Improvements
This commit is contained in:
Manuel Raynaud
2014-05-06 09:40:37 +02:00
2 changed files with 44 additions and 14 deletions

View File

@@ -12,6 +12,7 @@
namespace Thelia\Core\Template\Smarty\Assets; namespace Thelia\Core\Template\Smarty\Assets;
use Thelia\Log\Tlog;
use Thelia\Tools\URL; use Thelia\Tools\URL;
use Thelia\Core\Template\Assets\AssetManagerInterface; use Thelia\Core\Template\Assets\AssetManagerInterface;
@@ -108,6 +109,27 @@ class SmartyAssetsManager
$templateDirectories = $smartyParser->getTemplateDirectories($templateDefinition->getType()); $templateDirectories = $smartyParser->getTemplateDirectories($templateDefinition->getType());
// if it's not a custom template and looking for a different origin (e.g. module)
// we first check if the asset is present in the default "source" (template)
// if not we take the default asset from the assetOrigin (module)
if (! $webAssetTemplate && $assetOrigin !== "0") {
if (isset($templateDirectories[$templateDefinition->getName()]["0"])) {
if (file_exists($templateDirectories[$templateDefinition->getName()]["0"] . DS . $file)) {
// the file exists, we take the default origin
$assetOrigin = "0";
}
}
}
if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) {
// we try with the default origin
if (! $webAssetTemplate && $assetOrigin !== "0") {
$assetOrigin = "0";
} else {
throw new \Exception("Failed to get real path of '/".dirname($file)."'");
}
}
if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) { if (! isset($templateDirectories[$templateDefinition->getName()][$assetOrigin])) {
throw new \Exception("Failed to get real path of '/".dirname($file)."'"); throw new \Exception("Failed to get real path of '/".dirname($file)."'");
} }
@@ -119,17 +141,21 @@ class SmartyAssetsManager
$file = str_replace('/', DS, $file); $file = str_replace('/', DS, $file);
} }
$url = $this->assetsManager->processAsset( $url = "";
$assetSource . DS . $file, // test if file exists before running the process
$assetSource . DS . self::$assetsDirectory, if (file_exists($assetSource . DS . $file)) {
$this->web_root . $this->path_relative_to_web_root, $url = $this->assetsManager->processAsset(
$templateDefinition->getPath(), $assetSource . DS . $file,
$assetOrigin, $assetSource . DS . self::$assetsDirectory,
URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */), $this->web_root . $this->path_relative_to_web_root,
$assetType, $templateDefinition->getPath(),
$filters, $assetOrigin,
$debug URL::getInstance()->absoluteUrl($this->path_relative_to_web_root, null, URL::PATH_TO_FILE /* path only */),
); $assetType,
$filters,
$debug
);
}
return $url; return $url;
} }
@@ -138,10 +164,13 @@ class SmartyAssetsManager
{ {
// Opening tag (first call only) // Opening tag (first call only)
if ($repeat) { if ($repeat) {
$url = $this->computeAssetUrl($assetType, $params, $template); $url = "";
try {
$url = $this->computeAssetUrl($assetType, $params, $template);
} catch (\Exception $ex) {
Tlog::getInstance()->addWarning("Failed to get real path of " . $params['file']);
}
$template->assign('asset_url', $url); $template->assign('asset_url', $url);
} elseif (isset($content)) { } elseif (isset($content)) {
return $content; return $content;
} }

View File

@@ -22,6 +22,7 @@
/*************************************************************************************/ /*************************************************************************************/
namespace Front\Controller; namespace Front\Controller;
use Front\Front;
use Propel\Runtime\Exception\PropelException; use Propel\Runtime\Exception\PropelException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Thelia\Cart\CartTrait; use Thelia\Cart\CartTrait;