protected $_currentTag;
- public $templateFolders = array();
+ private $environment;
public $templateContent = '';
public $_extendedTemplate = '';
- function __construct($template_file, $folders=array(), $load=true)
+ function __construct($template_file, $environment, $load=true)
{
$allowedtags = IPF::get('template_tags', array());
$this->_allowedTags = array_merge($allowedtags, $this->_allowedTags);
$this->_allowedInExpr = array_merge($this->_vartype, $this->_op);
$this->_allowedAssign = array_merge($this->_vartype, $this->_assignOp,
$this->_op);
- $this->templateFolders = $folders;
+ $this->environment = $environment;
if ($load) {
- $this->loadTemplateFile($template_file);
+ $this->templateContent = $this->environment->loadTemplateFile($template_file);
}
}
if (strlen($this->_extendedTemplate) > 0) {
// The template of interest is now the extended template
// as we are not in a base template
- $this->loadTemplateFile($this->_extendedTemplate);
+ $this->templateContent = $this->environment->loadTemplateFile($this->_extendedTemplate);
$this->_sourceFile = $this->_extendedTemplate;
$this->compileBlocks(); //It will recurse to the base template.
} else {
}
}
- function loadTemplateFile($file)
- {
- // FIXME: Very small security check, could be better.
- if (strpos($file, '..') !== false) {
- throw new IPF_Exception(sprintf(__('Template file contains invalid characters: %s'), $file));
- }
- foreach ($this->templateFolders as $folder) {
- if (file_exists($folder.'/'.$file)) {
- $this->templateContent = file_get_contents($folder.'/'.$file);
- return;
- }
- }
- // File not found in all the folders.
- throw new IPF_Exception(sprintf(__('Template file not found: %s'), $file));
- }
-
function _callback($matches)
{
list(,$tag, $firstcar) = $matches;
case 'include':
// XXX fixme: Will need some security check, when online editing.
$argfct = preg_replace('!^[\'"](.*)[\'"]$!', '$1', $args);
- $_comp = new IPF_Template_Compiler($argfct, $this->templateFolders);
+ $_comp = new IPF_Template_Compiler($argfct, $this->environment);
$res = $_comp->compile();
$this->updateModifierStack($_comp);
break;
$this->cache = $cache;
}
+ public function loadTemplateFile($filename)
+ {
+ // FIXME: Very small security check, could be better.
+ if (strpos($filename, '..') !== false) {
+ throw new IPF_Exception(sprintf(__('Template file contains invalid characters: %s'), $filename));
+ }
+ foreach ($this->folders as $folder) {
+ if (file_exists($folder.'/'.$filename)) {
+ return file_get_contents($folder.'/'.$filename);
+ }
+ }
+ throw new IPF_Exception(sprintf(__('Template file not found: %s'), $filename));
+ }
+
public function getCompiledTemplateName($template)
{
$_tmp = var_export($this->folders, true);