From f304c29ceba9dff6521d50497955c5e9e04e69ce Mon Sep 17 00:00:00 2001 From: ikkez Date: Mon, 20 Apr 2015 23:36:06 +0200 Subject: [PATCH] configurable token filters --- base.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/base.php b/base.php index bd18532b..6da85d67 100644 --- a/base.php +++ b/base.php @@ -2434,16 +2434,6 @@ function($val) use($fw) { ); } - /** - * build an url from alias name - * @return string - * @param $key string - * @param $arg string - **/ - function alias($key,$arg=null) { - return Base::instance()->alias($key,$arg); - } - /** * Create sandbox for template execution * @return string @@ -2520,7 +2510,14 @@ class Preview extends View { protected //! MIME type - $mime; + $mime, + //! token filter + $filter = array( + 'esc'=>'$this->esc', + 'raw'=>'$this->raw', + 'alias'=>'\Base::instance()->alias', + 'format'=>'\Base::instance()->format' + ); /** * Convert token to variable @@ -2532,6 +2529,18 @@ function token($str) { Base::instance()->compile($str))); } + /** + * register token filter + * @param string $key + * @param string $func + * @return array + */ + function filter($key=NULL,$func=NULL) { + if (!$key) + return array_keys($this->filter); + $this->filter[$key]=$func; + } + /** * Assemble markup * @return string @@ -2549,8 +2558,7 @@ function($expr) use($self) { $str,$parts)) { $str=$parts[1]; foreach (Base::instance()->split($parts[2]) as $func) - $str=(($func=='format')?'\Base::instance()':'$this'). - '->'.$func.'('.$str.')'; + $str=$this->filter[$func].'('.$str.')'; } return ''. (isset($expr[3])?$expr[3]."\n":'');