From 91e0733e8ef0640df20c18e91c61564458b091d1 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sat, 7 Jan 2017 16:14:04 -0800 Subject: Comanche: add greater/less than (plus greater/less than or equal) conditionals --- Zotlabs/Render/Comanche.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Render/Comanche.php') diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php index a9ca023e5..8e36f52c2 100644 --- a/Zotlabs/Render/Comanche.php +++ b/Zotlabs/Render/Comanche.php @@ -131,7 +131,12 @@ class Comanche { // [if $config.system.foo ~= baz] which will check if get_config('system','foo') contains the string 'baz'; // [if $config.system.foo == baz] which will check if get_config('system','foo') is the string 'baz'; // [if $config.system.foo != baz] which will check if get_config('system','foo') is not the string 'baz'; - // You may check numeric entries, but these checks are evaluated as strings. + // [if $config.system.foo >= 3] which will check if get_config('system','foo') is greater than or equal to 3; + // [if $config.system.foo > 3] which will check if get_config('system','foo') is greater than 3; + + // [if $config.system.foo <= 3] which will check if get_config('system','foo') is less than or equal to 3; + // [if $config.system.foo < 3] which will check if get_config('system','foo') is less than 3; + // [if $config.system.foo {} baz] which will check if 'baz' is an array element in get_config('system','foo') // [if $config.system.foo {*} baz] which will check if 'baz' is an array key in get_config('system','foo') // [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo'); @@ -158,6 +163,31 @@ class Comanche { return false; } + if(preg_match('/[\$](.*?)\s\>\=\s(.*?)$/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if($x >= trim($matches[2])) + return true; + return false; + } + if(preg_match('/[\$](.*?)\s\<\=\s(.*?)$/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if($x <= trim($matches[2])) + return true; + return false; + } + if(preg_match('/[\$](.*?)\s\>\s(.*?)$/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if($x > trim($matches[2])) + return true; + return false; + } + if(preg_match('/[\$](.*?)\s\>\s(.*?)$/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if($x < trim($matches[2])) + return true; + return false; + } + if(preg_match('/[\$](.*?)\s\{\}\s(.*?)$/',$s,$matches)) { $x = $this->get_condition_var($matches[1]); if(is_array($x) && in_array(trim($matches[2]),$x)) -- cgit v1.2.3