aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
authorgit-marijus <mario@mariovavti.com>2017-05-09 10:16:11 +0200
committerGitHub <noreply@github.com>2017-05-09 10:16:11 +0200
commit9a0400c93a0e809c9bc32daa1aea0a78406b6676 (patch)
treefad8b5551d7eb3967f00c0753b75aa296b89e394 /Zotlabs
parent13b5eb0ad8cbeaab9ef996f0835425de331efd70 (diff)
parent0be74c655188d02c7242fd927d356669c268ab3d (diff)
downloadvolse-hubzilla-9a0400c93a0e809c9bc32daa1aea0a78406b6676.tar.gz
volse-hubzilla-9a0400c93a0e809c9bc32daa1aea0a78406b6676.tar.bz2
volse-hubzilla-9a0400c93a0e809c9bc32daa1aea0a78406b6676.zip
Merge pull request #763 from anaqreon/dev
Implemented switch statement logic in Comanche layout parser.
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Render/Comanche.php44
1 files changed, 43 insertions, 1 deletions
diff --git a/Zotlabs/Render/Comanche.php b/Zotlabs/Render/Comanche.php
index 5c1ca7d10..beee9796e 100644
--- a/Zotlabs/Render/Comanche.php
+++ b/Zotlabs/Render/Comanche.php
@@ -18,7 +18,49 @@ class Comanche {
$s = str_replace($mtch[0], '', $s);
}
}
-
+
+ /*
+ * This section supports the "switch" statement of the form given by the following
+ * example. The [default][/default] block must be the last in the arbitrary
+ * list of cases. The first case that matches the switch variable is used
+ * and the rest are not evaluated.
+ *
+ * [switch observer.language]
+ * [case de]
+ * [block]german-content[/block]
+ * [/case]
+ * [case es]
+ * [block]spanish-content[/block]
+ * [/case]
+ * [default]
+ * [block]english-content[/block]
+ * [/default]
+ * [/switch]
+ */
+
+ $cnt = preg_match_all("/\[switch (.*?)\](.*?)\[default\](.*?)\[\/default\]\s*\[\/switch\]/ism", $s, $matches, PREG_SET_ORDER);
+ if($cnt) {
+ foreach($matches as $mtch) {
+ $switch_done = 0;
+ $switch_var = $this->get_condition_var($mtch[1]);
+ $default = $mtch[3];
+ $cases = array();
+ $cntt = preg_match_all("/\[case (.*?)\](.*?)\[\/case\]/ism", $mtch[2], $cases, PREG_SET_ORDER);
+ if($cntt) {
+ foreach($cases as $case) {
+ if($case[1] === $switch_var) {
+ $switch_done = 1;
+ $s = str_replace($mtch[0], $case[2], $s);
+ break;
+ }
+ }
+ if($switch_done === 0) {
+ $s = str_replace($mtch[0], $default, $s);
+ }
+ }
+ }
+ }
+
$cnt = preg_match_all("/\[if (.*?)\](.*?)\[else\](.*?)\[\/if\]/ism", $s, $matches, PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {