aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorredmatrix <mike@macgirvin.com>2016-08-26 13:58:37 -0700
committerredmatrix <mike@macgirvin.com>2016-08-26 13:58:37 -0700
commit86dd67f57da2f36ab4d4706ce0022e0fd4579b76 (patch)
tree80c9f60e4ff96cd3cc2d77249749c37a55b66b14
parent8a2b96c2f950f828635441f357acfad94cea1266 (diff)
downloadvolse-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.
-rw-r--r--Zotlabs/Render/Comanche.php46
-rw-r--r--doc/comanche.bb51
2 files changed, 73 insertions, 24 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;
}
diff --git a/doc/comanche.bb b/doc/comanche.bb
index 6a96d5251..177a4252d 100644
--- a/doc/comanche.bb
+++ b/doc/comanche.bb
@@ -65,17 +65,23 @@ By default, $nav is placed in the &quot;nav&quot; page region and $content is pl
To select a theme for your page, use the 'theme' tag.
[code]
- [theme]apw[/theme]
+ [theme]suckerberg[/theme]
[/code]
-This will select the theme named &quot;apw&quot;. By default your channel's preferred theme will be used.
+This will select the theme named &quot;suckerberg&quot;. By default your channel's preferred theme will be used.
[code]
- [theme=passion]apw[/theme]
+ [theme=passion]suckerberg[/theme]
[/code]
-This will select the theme named &quot;apw&quot; and select the &quot;passion&quot; schema (theme variant).
+This will select the theme named &quot;suckerberg&quot; and select the &quot;passion&quot; schema (theme variant). Alternatively it may be possible to use a condensed theme notation for this.
+[code]
+ [theme]suckerberg:passion[/theme]
+
+[/code]
+
+The condensed notation isn't part of Comanche itself but is recognised by the $Projectname platform as a theme specifier.
[b]Regions[/b]
Each region has a name, as noted above. You will specify the region of interest using a 'region' tag, which includes the name. Any content you wish placed in this region should be placed between the opening region tag and the closing tag.
@@ -164,7 +170,42 @@ The 'comment' tag is used to delimit comments. These comments will not appear on
[comment]This is a comment[/comment]
[/code]
-
+
+[b]Conditional Execution[/b]
+You can use an 'if' construct to make decisions. These are currently based on system configuration variable or the current observer.
+
+[code]
+ [if $config.system.foo]
+ ... the configuration variable system.foo evaluates to 'true'.
+ [else]
+ ... the configuration variable system.foo evaluates to 'false'.
+ [/if]
+
+ [if $observer]
+ ... this content will only be show to authenticated viewers
+ [/if]
+
+[/code]
+
+ The 'else' clause is optional.
+
+ Several tests are supported besides boolean evaluation.
+
+[code]
+ [if $config.system.foo == bar]
+ ... the configuration variable system.foo is equal to the string 'bar'
+ [/if]
+ [if $config.system.foo != bar]
+ ... the configuration variable system.foo is not equal to the string 'bar'
+ [/if]
+ [if $config.system.foo {} bar ]
+ ... the configuration variable system.foo is a simple array containing a value 'bar'
+ [/if]
+ [if $config.system.foo {*} bar]
+ ... the configuration variable system.foo is a simple array containing a key named 'bar'
+ [/if]
+[/code]
+
[b]Complex Example[/b]
[code]
[comment]use an existing page template which provides a banner region plus 3 columns beneath it[/comment]