diff options
author | Mario <mario@mariovavti.com> | 2020-01-31 10:34:55 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-01-31 10:34:55 +0100 |
commit | 69b25e490e5effba78fcdd9fb991fe71b7523138 (patch) | |
tree | bed30f592e179da1a842114370bdd402cafb2495 /Zotlabs/Module/Item.php | |
parent | c50a311ff32d7361d0809d87b03be1b4ec25b783 (diff) | |
parent | b8d7647c48f9683909476d14c6f94195980b15a2 (diff) | |
download | volse-hubzilla-69b25e490e5effba78fcdd9fb991fe71b7523138.tar.gz volse-hubzilla-69b25e490e5effba78fcdd9fb991fe71b7523138.tar.bz2 volse-hubzilla-69b25e490e5effba78fcdd9fb991fe71b7523138.zip |
Merge branch 'dev' into 'dev'
polls and other backend z6 compat work
See merge request hubzilla/core!1825
Diffstat (limited to 'Zotlabs/Module/Item.php')
-rw-r--r-- | Zotlabs/Module/Item.php | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 1a25e54df..8b4bbae91 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -718,7 +718,14 @@ class Item extends Controller { // BBCODE alert: the following functions assume bbcode input // and will require alternatives for alternative content-types (text/html, text/markdown, text/plain, etc.) // we may need virtual or template classes to implement the possible alternatives - + + $obj = $this->extract_poll_data($body); + if ($obj) { + $datarray['obj'] = $obj; + $obj_type = 'Question'; + } + + if(strpos($body,'[/summary]') !== false) { $match = ''; @@ -1387,5 +1394,57 @@ class Item extends Controller { return $ret; } - + function extract_poll_data(&$body) { + + $multiple = false; + + if (strpos($body,'[/question]') === false && strpos($body,'[/answer]') === false) { + return false; + } + if (strpos($body,'[nobb]') !== false) { + return false; + } + + + $obj = []; + $ptr = []; + $matches = null; + $obj['type'] = 'Question'; + + if (preg_match_all('/\[answer\](.*?)\[\/answer\]/',$body,$matches,PREG_SET_ORDER)) { + foreach ($matches as $match) { + $ptr[] = [ 'name' => $match[1], 'type' => 'Note', 'replies' => [ 'type' => 'Collection', 'totalItems' => 0 ]]; + $body = str_replace('[answer]' . $match[1] . '[/answer]', EMPTY_STR, $body); + } + } + + $matches = null; + + if (preg_match('/\[question\](.*?)\[\/question\]/',$body,$matches)) { + $obj['content'] = bbcode($matches[1]); + $body = str_replace('[question]' . $matches[1] . '[/question]', $matches[1], $body); + $obj['oneOf'] = $ptr; + } + + $matches = null; + + if (preg_match('/\[question=multiple\](.*?)\[\/question\]/',$body,$matches)) { + $obj['content'] = bbcode($matches[1]); + $body = str_replace('[question=multiple]' . $matches[1] . '[/question]', $matches[1], $body); + $obj['anyOf'] = $ptr; + } + + $matches = null; + + if (preg_match('/\[ends\](.*?)\[\/ends\]',$body,$matches)) { + $obj['endTime'] = datetime_convert(date_default_timezone_get(),'UTC', $matches[1],ATOM_TIME); + $body = str_replace('[ends]' . $match[1] . '[/ends]', EMPTY_STR, $body); + } + + return $obj; + + } + + + } |