From d0b7317e10254490acbe748d1d8c1e04aaf8be6b Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 27 Jun 2012 21:09:07 +0200 Subject: Added new Tags to the standard library. * ste:in_array checks, if a value is in an array * ste:join joins an array with a glue string * ste:split splits a string with a delimiter to an array * ste:array_add adds an element to an array. --- stupid_template_engine.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'stupid_template_engine.php') diff --git a/stupid_template_engine.php b/stupid_template_engine.php index 6acb6d7..e8e78ec 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -1396,6 +1396,44 @@ class STEStandardLibrary { return @strftime($sub($ste), empty($params["timestamp"]) ? @time() : (int) $params["timestamp"]); } + + static public function in_array($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + $ar = &$ste->get_var_reference($params["array"], False); + if(!is_array($ar)) + return ""; + return in_array($sub($ste), $ar) ? "y" : ""; + } + + static public function join($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + return implode($sub($ste), $ste->get_var_by_name($params["array"])); + } + + static public function split($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + if(empty($params["delim"])) + throw new RuntimeError("Missing delim parameter in ."); + $ste->set_var_by_name($params["array"], explode($params["delim"], $sub($ste))); + } + + static public function array_add($ste, $params, $sub) + { + if(empty($params["array"])) + throw new RuntimeError("Missing array parameter in ."); + + $ar = &$ste->get_var_reference($params["array"], True); + if(empty($params["key"])) + $ar[] = $sub($ste); + else + $ar[$params["key"]] = $sub($ste); + } } ?> \ No newline at end of file -- cgit v1.2.3-70-g09d2