diff options
author | redmatrix <mike@macgirvin.com> | 2016-08-26 13:58:37 -0700 |
---|---|---|
committer | redmatrix <mike@macgirvin.com> | 2016-08-26 13:58:37 -0700 |
commit | 86dd67f57da2f36ab4d4706ce0022e0fd4579b76 (patch) | |
tree | 80c9f60e4ff96cd3cc2d77249749c37a55b66b14 /Zotlabs/Render/Comanche.php | |
parent | 8a2b96c2f950f828635441f357acfad94cea1266 (diff) | |
download | volse-hubzilla-86dd67f57da2f36ab4d4706ce0022e0fd4579b76.tar.gz volse-hubzilla-86dd67f57da2f36ab4d4706ce0022e0fd4579b76.tar.bz2 volse-hubzilla-86dd67f57da2f36ab4d4706ce0022e0fd4579b76.zip |
comanche: generalise the conditional variable usage and add $observer as a test. Update comanche doco to reflect recent changes.
Diffstat (limited to 'Zotlabs/Render/Comanche.php')
-rw-r--r-- | Zotlabs/Render/Comanche.php | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php index ff5aa7140..b0efa5e0b 100644 --- a/Zotlabs/Render/Comanche.php +++ b/Zotlabs/Render/Comanche.php @@ -99,7 +99,18 @@ class Comanche { } } - + function get_condition_var($v) { + if($v) { + $x = explode('.',$v); + if($x[0] == 'config') + return get_config($x[1],$x[2]); + elseif($x[0] === 'observer') + return get_observer_hash(); + else + return false; + } + return false; + } function test_condition($s) { @@ -112,39 +123,36 @@ class Comanche { // [if $config.system.foo] which will check for a return of a true condition for get_config('system','foo'); // The values 0, '', an empty array, and an unset value will all evaluate to false. - if(preg_match('/[\$]config[\.](.*?)\s\=\=\s(.*?)$/',$s,$matches)) { - $x = explode('.',$matches[1]); - if(get_config(trim($x[0]),trim($x[1])) == trim($matches[2])) + 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('/[\$]config[\.](.*?)\s\!\=\s(.*?)$/',$s,$matches)) { - $x = explode('.',$matches[1]); - if(get_config(trim($x[0]),trim($x[1])) != trim($matches[2])) + 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('/[\$]config[\.](.*?)\s\{\}\s(.*?)$/',$s,$matches)) { - $x = explode('.',$matches[1]); - $y = get_config(trim($x[0]),trim($x[1])); - if(is_array($y) && in_array(trim($matches[2]),$y)) + if(preg_match('/[\$](.*?)\s\{\}\s(.*?)$/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if(is_array($x) && in_array(trim($matches[2]),$x)) return true; return false; } - if(preg_match('/[\$]config[\.](.*?)\s\{\*\}\s(.*?)$/',$s,$matches)) { - $x = explode('.',$matches[1]); - $y = get_config(trim($x[0]),trim($x[1])); - if(is_array($y) && array_key_exists(trim($matches[2]),$y)) + if(preg_match('/[\$](.*?)\s\{\*\}\s(.*?)$/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if(is_array($x) && array_key_exists(trim($matches[2]),$x)) return true; return false; } - - if(preg_match('/[\$]config[\.](.*?)/',$s,$matches)) { - $x = explode('.',$matches[1]); - if(get_config(trim($x[0]),trim($x[1]))) + if(preg_match('/[\$](.*?)/',$s,$matches)) { + $x = $this->get_condition_var($matches[1]); + if($x) return true; return false; } |