public $_usedModifiers = array();
- protected $_allowedTags = array(
- 'url' => 'IPF_Template_Tag_Url',
- );
-
- protected $_extraTags = array();
-
protected $_blockStack = array();
protected $_transStack = array();
function __construct($templateContent, $environment)
{
- $allowedtags = IPF::get('template_tags', array());
- $this->_allowedTags = array_merge($allowedtags, $this->_allowedTags);
$modifiers = IPF::get('template_modifiers', array());
$this->_modifier = array_merge($modifiers, $this->_modifier);
- foreach ($this->_allowedTags as $name=>$model) {
- $this->_extraTags[$name] = new $model();
- }
-
$this->templateContent = $templateContent;
$this->environment = $environment;
}
$this->updateModifierStack($_comp);
break;
default:
- $_end = false;
+ $_start = true;
$oname = $name;
if (substr($name, 0, 1) == '/') {
- $_end = true;
+ $_start = false;
$name = substr($name, 1);
}
// Here we should allow custom blocks.
// Here we start the template tag calls at the template tag
// {tag ...} is not a block, so it must be a function.
- if (!isset($this->_allowedTags[$name])) {
+ if (!$this->environment->isTagAllowed($name)) {
trigger_error(sprintf(__('The function tag "%s" is not allowed.'), $name), E_USER_ERROR);
}
- $argfct = $this->_parseFinal($args, self::$allowedAssign);
// $argfct is a string that can be copy/pasted in the PHP code
// but we need the array of args.
- $res = '';
- if (isset($this->_extraTags[$name])) {
- if (false == $_end) {
- if (method_exists($this->_extraTags[$name], 'start')) {
- $res .= '$_extra_tag = IPF::factory(\''.$this->_allowedTags[$name].'\', $t); $_extra_tag->start('.$argfct.'); ';
- }
- if (method_exists($this->_extraTags[$name], 'genStart')) {
- $res .= $this->_extraTags[$name]->genStart();
- }
- } else {
- if (method_exists($this->_extraTags[$name], 'end')) {
- $res .= '$_extra_tag = IPF::factory(\''.$this->_allowedTags[$name].'\', $t); $_extra_tag->end('.$argfct.'); ';
- }
- if (method_exists($this->_extraTags[$name], 'genEnd')) {
- $res .= $this->_extraTags[$name]->genEnd();
- }
- }
- }
- if ($res == '') {
- trigger_error(sprintf(__('The function tag "{%s ...}" is not supported.'), $oname), E_USER_ERROR);
+ $argfct = $this->_parseFinal($args, self::$allowedAssign);
+
+ $res = '$_extra_tag = new '.$this->environment->allowedTags[$name].'($t);';
+ if ($_start) {
+ $res .= '$_extra_tag->start('.$argfct.'); ';
+ } else {
+ $res .= '$_extra_tag->end('.$argfct.'); ';
}
}
return $res;
abstract public function getCompiledTemplateName($template);
- private static $defaultEnvironment = null;
+ public $allowedTags = array();
- public static function getDefault()
+ public function isTagAllowed($name)
{
- if (!self::$defaultEnvironment) {
- $dirs = array();
-
- $projectTemplates = IPF::get('project_path') . '/templates';
- if (is_dir($projectTemplates))
- $dirs[] = $projectTemplates;
-
- foreach (IPF_Project::getInstance()->appList() as $app) {
- $applicationTemplates = $app->getPath() . 'templates';
- if (is_dir($applicationTemplates))
- $dirs[] = $applicationTemplates;
- }
-
- self::$defaultEnvironment = new IPF_Template_Environment_FileSystem($dirs, IPF::get('tmp'));
- }
- return self::$defaultEnvironment;
+ return isset($this->allowedTags[$name]);
}
}