self::$defaultEnvironment = new IPF_Template_Environment_FileSystem($dirs, IPF::get('tmp'));
- self::$defaultEnvironment->allowedTags['url'] = 'IPF_Template_Tag_Url';
- self::$defaultEnvironment->allowedTags = array_merge(IPF::get('template_tags', array()), self::$defaultEnvironment->allowedTags);
+ self::$defaultEnvironment->tags['url'] = 'IPF_Template_Tag_Url';
+ // extra tags
+ self::$defaultEnvironment->tags = array_merge(IPF::get('template_tags', array()), self::$defaultEnvironment->tags);
+
+ // extra modifiers
+ self::$defaultEnvironment->modifiers = array_merge(IPF::get('template_modifiers', array()), self::$defaultEnvironment->modifiers);
}
return self::$defaultEnvironment;
}
self::$allowedForeach = array_merge(self::$allowedInExpr, array(T_AS));
}
- protected $_modifier = array(
- 'upper' => 'strtoupper',
- 'lower' => 'strtolower',
- 'escxml' => 'htmlspecialchars',
- 'escape' => 'IPF_Template_Modifier::escape',
- 'strip_tags' => 'strip_tags',
- 'escurl' => 'rawurlencode',
- 'capitalize' => 'ucwords',
- 'debug' => 'print_r', // Not var_export because of recursive issues.
- 'fulldebug' => 'var_export',
- 'count' => 'count',
- 'nl2br' => 'nl2br',
- 'trim' => 'trim',
- 'unsafe' => 'IPF_Template_SafeString::markSafe',
- 'safe' => 'IPF_Template_SafeString::markSafe',
- 'date' => 'IPF_Template_Modifier::dateFormat',
- 'time' => 'IPF_Template_Modifier::timeFormat',
- 'floatformat' => 'IPF_Template_Modifier::floatFormat',
- 'limit_words' => 'IPF_Template_Modifier::limitWords',
- 'limit_chars' => 'IPF_Template_Modifier::limitCharacters',
- );
-
protected $_literals;
protected $_blockStack = array();
function __construct($templateContent, $environment)
{
- $modifiers = IPF::get('template_modifiers', array());
- $this->_modifier = array_merge($modifiers, $this->_modifier);
-
$this->templateContent = $templateContent;
$this->environment = $environment;
}
return '';
}
- if (isset($this->_modifier[$m[1]])) {
+ if ($this->environment->hasModifier($m[1])) {
trigger_error(sprintf(__('Unknown modifier: (%s) %s'), $expr, $m[1]), E_USER_ERROR);
return '';
}
- $modifier = $this->_modifier[$m[1]];
+ $mod = $this->environment->getModifier($m[1]);
if (isset($m[2])) {
- $res = $modifier.'('.$res.','.$m[2].')';
+ $res = $mod.'('.$res.','.$m[2].')';
} else {
- $res = $modifier.'('.$res.')';
+ $res = $mod.'('.$res.')';
}
}
return $res;
// but we need the array of args.
$argfct = $this->_parseFinal($args, self::$allowedAssign);
- $res = '$_extra_tag = new '.$this->environment->allowedTags[$name].'($t);';
+ $res = '$_extra_tag = new '.$this->environment->getTag($name).'($t);';
if ($_start) {
$res .= '$_extra_tag->start('.$argfct.'); ';
} else {
abstract public function getCompiledTemplateName($template);
- public $allowedTags = array();
+ // Dictionary of allowed tags (tag name => class)
+ public $tags = array();
public function isTagAllowed($name)
{
- return isset($this->allowedTags[$name]);
+ return isset($this->tags[$name]);
+ }
+
+ public function getTag($name)
+ {
+ if (isset($this->tags[$name]))
+ return $this->tags[$name];
+ else
+ throw new IPF_Exception_Template('Tag '.$name.' is not defined.');
+ }
+
+ // Dictionary of modifiers (modifier name => function)
+ public $modifiers = array(
+ 'upper' => 'strtoupper',
+ 'lower' => 'strtolower',
+ 'escxml' => 'htmlspecialchars',
+ 'escape' => 'IPF_Template_Modifier::escape',
+ 'strip_tags' => 'strip_tags',
+ 'escurl' => 'rawurlencode',
+ 'capitalize' => 'ucwords',
+ 'debug' => 'print_r', // Not var_export because of recursive issues.
+ 'fulldebug' => 'var_export',
+ 'count' => 'count',
+ 'nl2br' => 'nl2br',
+ 'trim' => 'trim',
+ 'unsafe' => 'IPF_Template_SafeString::markSafe',
+ 'safe' => 'IPF_Template_SafeString::markSafe',
+ 'date' => 'IPF_Template_Modifier::dateFormat',
+ 'time' => 'IPF_Template_Modifier::timeFormat',
+ 'floatformat' => 'IPF_Template_Modifier::floatFormat',
+ 'limit_words' => 'IPF_Template_Modifier::limitWords',
+ 'limit_chars' => 'IPF_Template_Modifier::limitCharacters',
+ );
+
+ public function hasModifier($name)
+ {
+ return isset($this->modifiers[$name]);
+ }
+
+ public function getModifier($name)
+ {
+ if (isset($this->modifiers[$name]))
+ return $this->modifiers[$name];
+ else
+ throw new IPF_Exception_Template('Modifier '.$name.' is not defined.');
}
}