aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2012-03-02 17:22:16 +0100
committerFabio Comuni <fabrix.xm@gmail.com>2012-03-02 17:22:16 +0100
commit8a51e29824fc2569ac1d0def3070bee7c0552231 (patch)
treec47f0561e2ac7faba057099795046b0092414928
parentaef737f37637270b4f79ea390ee23a61f7fcb4ba (diff)
downloadvolse-hubzilla-8a51e29824fc2569ac1d0def3070bee7c0552231.tar.gz
volse-hubzilla-8a51e29824fc2569ac1d0def3070bee7c0552231.tar.bz2
volse-hubzilla-8a51e29824fc2569ac1d0def3070bee7c0552231.zip
template proc: add variable filters
-rwxr-xr-xinclude/template_processor.php20
1 files changed, 15 insertions, 5 deletions
diff --git a/include/template_processor.php b/include/template_processor.php
index 111fc5849..90c6b2e65 100755
--- a/include/template_processor.php
+++ b/include/template_processor.php
@@ -160,15 +160,25 @@
private function var_replace($s){
$m = array();
- if (preg_match_all('/\$\[{0,1}([a-zA-Z0-9-_]+\.*)+\]{0,1}/', $s,$m)){
- foreach($m[0] as $var){
- $varn = str_replace(array("[","]"), array("",""), $var);
- $val = $this->_get_var($varn, true);
+ if (preg_match_all('/(\$\[{0,1}([a-zA-Z0-9-_]+\.*)+)(\|[a-zA-Z0-9-_]+)*\]{0,1}/', $s,$m)){
+ foreach($m[1] as $id=>$var){
+ $var = str_replace("[", "", $var);
+ $val = $this->_get_var($var, true);
+
+ // apply filters
+ if ($m[3][$id]!=""){
+ $filters = explode("|",trim($m[3][$id],"|"));
+ foreach($filters as $filter)
+ if (function_exists($filter))
+ $val=$filter($val);
+ }
if ($val!=KEY_NOT_EXISTS)
- $s = str_replace($var, $val, $s);
+ $s = str_replace($m[0][$id], $val, $s);
}
}
+
+
return $s;
}