aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Render/Comanche.php
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs/Render/Comanche.php')
-rw-r--r--Zotlabs/Render/Comanche.php65
1 files changed, 60 insertions, 5 deletions
diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php
index 820897ee9..91f0ce33a 100644
--- a/Zotlabs/Render/Comanche.php
+++ b/Zotlabs/Render/Comanche.php
@@ -99,18 +99,73 @@ 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') {
+ if(count($x) > 1) {
+ $y = \App::get_observer();
+ if(! $y)
+ return false;
+ if($x[1] == 'address')
+ return $y['xchan_addr'];
+ elseif($x[1] == 'name')
+ return $y['xchan_name'];
+ return false;
+ }
+ return get_observer_hash();
+ }
+ else
+ return false;
+ }
+ return false;
+ }
function test_condition($s) {
- // This is extensible. The first version of variable testing supports tests of the form
+ // This is extensible. The first version of variable testing supports tests of the forms:
+ // [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 {} 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');
// The values 0, '', an empty array, and an unset value will all evaluate to false.
- if(preg_match("/[\$]config[\.](.*?)/",$s,$matches)) {
- $x = explode('.',$s);
- if(get_config($x[1],$x[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('/[\$](.*?)\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))
+ return true;
+ return false;
+ }
+
+ 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('/[\$](.*?)/',$s,$matches)) {
+ $x = $this->get_condition_var($matches[1]);
+ if($x)
return true;
+ return false;
}
return false;