aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Render/Comanche.php
diff options
context:
space:
mode:
authorMario Vavti <mario@mariovavti.com>2017-03-08 09:39:46 +0100
committerMario Vavti <mario@mariovavti.com>2017-03-08 09:39:46 +0100
commitbc2b948f1f6e62b1c277a4042200bb6678956f3f (patch)
tree8586c30e495607eee23f16c0aad40974f0711275 /Zotlabs/Render/Comanche.php
parent23e3e2c50499fab52769929a448e73012fd915af (diff)
parentff9442474d07cce24c8f66db39ec34471c3874a2 (diff)
downloadvolse-hubzilla-bc2b948f1f6e62b1c277a4042200bb6678956f3f.tar.gz
volse-hubzilla-bc2b948f1f6e62b1c277a4042200bb6678956f3f.tar.bz2
volse-hubzilla-bc2b948f1f6e62b1c277a4042200bb6678956f3f.zip
Merge branch 2.2RC2.2
Diffstat (limited to 'Zotlabs/Render/Comanche.php')
-rw-r--r--Zotlabs/Render/Comanche.php57
1 files changed, 56 insertions, 1 deletions
diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php
index 562a9f791..5826063fd 100644
--- a/Zotlabs/Render/Comanche.php
+++ b/Zotlabs/Render/Comanche.php
@@ -99,13 +99,28 @@ class Comanche {
}
}
+ /**
+ * Currently supported condition variables:
+ *
+ * $config.xxx.yyy - get_config with cat = xxx and k = yyy
+ * $request - request uri for this page
+ * $observer.language - viewer's preferred language (closest match)
+ * $observer.address - xchan_addr or false
+ * $observer.name - xchan_name or false
+ * $observer - xchan_hash of observer or empty string
+ */
+
function get_condition_var($v) {
if($v) {
$x = explode('.',$v);
if($x[0] == 'config')
return get_config($x[1],$x[2]);
+ elseif($x[0] === 'request')
+ return $_SERVER['REQUEST_URI'];
elseif($x[0] === 'observer') {
if(count($x) > 1) {
+ if($x[1] == 'language')
+ return \App::$language;
$y = \App::get_observer();
if(! $y)
return false;
@@ -125,20 +140,35 @@ class Comanche {
function test_condition($s) {
// 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') 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');
// The values 0, '', an empty array, and an unset value will all evaluate to false.
+ if(preg_match('/[\$](.*?)\s\~\=\s(.*?)$/',$s,$matches)) {
+ $x = $this->get_condition_var($matches[1]);
+ if(stripos($x,trim($matches[2])) !== false)
+ 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]))
@@ -146,6 +176,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))