fix parser
This commit is contained in:
@@ -14,6 +14,9 @@ use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
|||||||
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
use Thelia\Core\Template\Exception\ResourceNotFoundException;
|
||||||
use Thelia\Core\Template\ParserContext;
|
use Thelia\Core\Template\ParserContext;
|
||||||
use Thelia\Core\Template\TemplateDefinition;
|
use Thelia\Core\Template\TemplateDefinition;
|
||||||
|
use Thelia\Model\ConfigQuery;
|
||||||
|
use Thelia\Core\Template\TemplateHelper;
|
||||||
|
use Imagine\Exception\InvalidArgumentException;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +35,12 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
protected $backOfficeTemplateDirectories = array();
|
protected $backOfficeTemplateDirectories = array();
|
||||||
protected $frontOfficeTemplateDirectories = array();
|
protected $frontOfficeTemplateDirectories = array();
|
||||||
|
|
||||||
protected $template = "";
|
protected $templateDirectories = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var TemplateDefinition
|
||||||
|
*/
|
||||||
|
protected $templateDefinition = "";
|
||||||
|
|
||||||
protected $status = 200;
|
protected $status = 200;
|
||||||
|
|
||||||
@@ -64,6 +72,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
$this->setCompileDir($compile_dir);
|
$this->setCompileDir($compile_dir);
|
||||||
$this->setCacheDir($cache_dir);
|
$this->setCacheDir($cache_dir);
|
||||||
|
|
||||||
|
|
||||||
$this->debugging = $debug;
|
$this->debugging = $debug;
|
||||||
|
|
||||||
// Prevent smarty ErrorException: Notice: Undefined index bla bla bla...
|
// Prevent smarty ErrorException: Notice: Undefined index bla bla bla...
|
||||||
@@ -71,7 +80,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
|
|
||||||
// Si on n'est pas en mode debug, activer le cache, avec une lifetime de 15mn, et en vérifiant que les templates sources n'ont pas été modifiés.
|
// Si on n'est pas en mode debug, activer le cache, avec une lifetime de 15mn, et en vérifiant que les templates sources n'ont pas été modifiés.
|
||||||
|
|
||||||
if ($debug) {
|
if($debug) {
|
||||||
$this->setCaching(Smarty::CACHING_OFF);
|
$this->setCaching(Smarty::CACHING_OFF);
|
||||||
$this->setForceCompile(true);
|
$this->setForceCompile(true);
|
||||||
} else {
|
} else {
|
||||||
@@ -80,6 +89,7 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
|
|
||||||
//$this->enableSecurity();
|
//$this->enableSecurity();
|
||||||
|
|
||||||
|
|
||||||
// The default HTTP status
|
// The default HTTP status
|
||||||
$this->status = 200;
|
$this->status = 200;
|
||||||
|
|
||||||
@@ -87,6 +97,46 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
$this->registerFilter('variable', array(__CLASS__, "theliaEscape"));
|
$this->registerFilter('variable', array(__CLASS__, "theliaEscape"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a template directory to the current template list
|
||||||
|
*
|
||||||
|
* @param unknown $templateType the template type (a TemplateDefinition type constant)
|
||||||
|
* @param string $templateName the template name
|
||||||
|
* @param string $templateDirectory path to the template dirtectory
|
||||||
|
* @param unknown $key ???
|
||||||
|
* @param string $unshift ??? Etienne ?
|
||||||
|
*/
|
||||||
|
public function addTemplateDirectory($templateType, $templateName, $templateDirectory, $key, $unshift = false) {
|
||||||
|
|
||||||
|
if(true === $unshift && isset($this->templateDirectories[$templateType][$templateName])) {
|
||||||
|
|
||||||
|
$this->templateDirectories[$templateType][$templateName] = array_merge(
|
||||||
|
array(
|
||||||
|
$key => $templateDirectory,
|
||||||
|
),
|
||||||
|
$this->templateDirectories[$templateType][$templateName]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$this->templateDirectories[$templateType][$templateName][$key] = $templateDirectory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the registeted template directories for a givent template type
|
||||||
|
*
|
||||||
|
* @param unknown $templateType
|
||||||
|
* @throws InvalidArgumentException
|
||||||
|
* @return multitype:
|
||||||
|
*/
|
||||||
|
public function getTemplateDirectories($templateType)
|
||||||
|
{
|
||||||
|
if (! isset($this->templateDirectories[$templateType])) {
|
||||||
|
throw new InvalidArgumentException("Failed to get template type %", $templateType);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->templateDirectories[$templateType];
|
||||||
|
}
|
||||||
|
|
||||||
public function removeBlankLines($tpl_source, \Smarty_Internal_Template $template)
|
public function removeBlankLines($tpl_source, \Smarty_Internal_Template $template)
|
||||||
{
|
{
|
||||||
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source);
|
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source);
|
||||||
@@ -101,72 +151,52 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addBackOfficeTemplateDirectory($templateName, $templateDirectory, $key)
|
|
||||||
{
|
|
||||||
$this->backOfficeTemplateDirectories[$templateName][$key] = $templateDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addFrontOfficeTemplateDirectory($templateName, $templateDirectory, $key)
|
|
||||||
{
|
|
||||||
$this->frontOfficeTemplateDirectories[$templateName][$key] = $templateDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param TemplateDefinition $templateDefinition
|
* @param TemplateDefinition $templateDefinition
|
||||||
*/
|
*/
|
||||||
public function setTemplate(TemplateDefinition $templateDefinition)
|
public function setTemplateDefinition(TemplateDefinition $templateDefinition)
|
||||||
{
|
{
|
||||||
$this->template = $templateDefinition->getPath();
|
$this->templateDefinition = $templateDefinition;
|
||||||
|
|
||||||
/* init template directories */
|
/* init template directories */
|
||||||
$this->setTemplateDir(array());
|
$this->setTemplateDir(array());
|
||||||
|
|
||||||
/* add main template directory */
|
|
||||||
$this->addTemplateDir($templateDefinition->getAbsolutePath(), 0);
|
|
||||||
|
|
||||||
/* define config directory */
|
/* define config directory */
|
||||||
$configDirectory = $templateDefinition->getAbsoluteConfigPath();
|
$configDirectory = THELIA_TEMPLATE_DIR . $this->getTemplate() . '/configs';
|
||||||
$this->setConfigDir($configDirectory);
|
$this->setConfigDir($configDirectory);
|
||||||
|
|
||||||
/* add modules template directories */
|
/* add modules template directories */
|
||||||
switch ($templateDefinition->getType()) {
|
$this->addTemplateDirectory(
|
||||||
case TemplateDefinition::FRONT_OFFICE:
|
$templateDefinition->getType(),
|
||||||
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
$templateDefinition->getName(),
|
||||||
if (isset($this->frontOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
THELIA_TEMPLATE_DIR . $this->getTemplate(),
|
||||||
foreach ($this->frontOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
'0',
|
||||||
$this->addTemplateDir($directory, $key);
|
true
|
||||||
}
|
);
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TemplateDefinition::BACK_OFFICE:
|
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
||||||
/* do not pass array directly to addTemplateDir since we cant control on keys */
|
if (isset($this->templateDirectories[$templateDefinition->getType()][$templateDefinition->getName()])) {
|
||||||
if (isset($this->backOfficeTemplateDirectories[$templateDefinition->getName()])) {
|
foreach($this->templateDirectories[$templateDefinition->getType()][$templateDefinition->getName()] as $key => $directory) {
|
||||||
foreach ($this->backOfficeTemplateDirectories[$templateDefinition->getName()] as $key => $directory) {
|
$this->addTemplateDir($directory, $key);
|
||||||
$this->addTemplateDir($directory, $key);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case TemplateDefinition::PDF:
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTemplateDefinition()
|
||||||
|
{
|
||||||
|
return $this->templateDefinition;
|
||||||
|
}
|
||||||
|
|
||||||
public function getTemplate()
|
public function getTemplate()
|
||||||
{
|
{
|
||||||
return $this->template;
|
return $this->templateDefinition->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a rendered template, either from file or ftom a string
|
* Return a rendered template, either from file or ftom a string
|
||||||
*
|
*
|
||||||
* @param string $resourceType either 'string' (rendering from a string) or 'file' (rendering a file)
|
* @param string $resourceType either 'string' (rendering from a string) or 'file' (rendering a file)
|
||||||
* @param string $resourceContent the resource content (a text, or a template file name)
|
* @param string $resourceContent the resource content (a text, or a template file name)
|
||||||
* @param array $parameters an associative array of names / value pairs
|
* @param array $parameters an associative array of names / value pairs
|
||||||
*
|
*
|
||||||
* @return string the rendered template text
|
* @return string the rendered template text
|
||||||
*/
|
*/
|
||||||
@@ -185,8 +215,8 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* Return a rendered template file
|
* Return a rendered template file
|
||||||
*
|
*
|
||||||
* @param string $realTemplateName the template name (from the template directory)
|
* @param string $realTemplateName the template name (from the template directory)
|
||||||
* @param array $parameters an associative array of names / value pairs
|
* @param array $parameters an associative array of names / value pairs
|
||||||
* @return string the rendered template text
|
* @return string the rendered template text
|
||||||
*/
|
*/
|
||||||
public function render($realTemplateName, array $parameters = array())
|
public function render($realTemplateName, array $parameters = array())
|
||||||
@@ -201,8 +231,8 @@ class SmartyParser extends Smarty implements ParserInterface
|
|||||||
/**
|
/**
|
||||||
* Return a rendered template text
|
* Return a rendered template text
|
||||||
*
|
*
|
||||||
* @param string $templateText the template text
|
* @param string $templateText the template text
|
||||||
* @param array $parameters an associative array of names / value pairs
|
* @param array $parameters an associative array of names / value pairs
|
||||||
* @return string the rendered template text
|
* @return string the rendered template text
|
||||||
*/
|
*/
|
||||||
public function renderString($templateText, array $parameters = array())
|
public function renderString($templateText, array $parameters = array())
|
||||||
|
|||||||
Reference in New Issue
Block a user