aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Item.php
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2020-01-30 15:56:33 -0800
committerzotlabs <mike@macgirvin.com>2020-01-30 15:56:33 -0800
commit989443a5698adf5e7a93f874048699526aa103a7 (patch)
treef5db527455879b0d39b63a4356c25bb260858a1a /Zotlabs/Module/Item.php
parente9b2dacb61ad5a4c81a8b0a19db92adecb51b2f5 (diff)
downloadvolse-hubzilla-989443a5698adf5e7a93f874048699526aa103a7.tar.gz
volse-hubzilla-989443a5698adf5e7a93f874048699526aa103a7.tar.bz2
volse-hubzilla-989443a5698adf5e7a93f874048699526aa103a7.zip
basic poll support and patch to not call System::get_platform_name() within t() unless needed. Polls probably need refining and have not yet been fully tested after porting
Diffstat (limited to 'Zotlabs/Module/Item.php')
-rw-r--r--Zotlabs/Module/Item.php63
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;
+
+ }
+
+
+
}