aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs
diff options
context:
space:
mode:
Diffstat (limited to 'Zotlabs')
-rw-r--r--Zotlabs/Lib/Activity.php82
-rw-r--r--Zotlabs/Lib/NativeWikiPage.php7
-rw-r--r--Zotlabs/Module/Apschema.php5
-rw-r--r--Zotlabs/Module/Item.php61
4 files changed, 143 insertions, 12 deletions
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 5cb111381..02ec7614e 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -504,10 +504,47 @@ class Activity {
}
}
}
+ if ($item['iconfig']) {
+ foreach ($item['iconfig'] as $att) {
+ if ($att['sharing']) {
+ $value = ((preg_match('|^a:[0-9]+:{.*}$|s', $att['v'])) ? unserialize($att['v']) : $att['v']);
+ $ret[] = [ 'type' => 'PropertyValue', 'name' => 'zot.' . $att['cat'] . '.' . $att['k'], 'value' => $value ];
+ }
+ }
+ }
return $ret;
}
+ static function decode_iconfig($item) {
+
+ $ret = [];
+
+ if (is_array($item['attachment']) && $item['attachment']) {
+ $ptr = $item['attachment'];
+ if (! array_key_exists(0,$ptr)) {
+ $ptr = [ $ptr ];
+ }
+ foreach ($ptr as $att) {
+ $entry = [];
+ if ($att['type'] === 'PropertyValue') {
+ if (array_key_exists('name',$att) && $att['name']) {
+ $key = explode('.',$att['name']);
+ if (count($key) === 3 && $key[0] === 'zot') {
+ $entry['cat'] = $key[1];
+ $entry['k'] = $key[2];
+ $entry['v'] = $att['value'];
+ $entry['sharing'] = '1';
+ $ret[] = $entry;
+ }
+ }
+ }
+ }
+ }
+ return $ret;
+ }
+
+
static function decode_attachment($item) {
@@ -1636,8 +1673,11 @@ class Activity {
- static function update_poll($item,$mid,$content) {
+ static function update_poll($item,$post) {
$multi = false;
+ $mid = $post['mid'];
+ $content = $post['title'];
+
if (! $item) {
return false;
}
@@ -1646,6 +1686,31 @@ class Activity {
if ($o && array_key_exists('anyOf',$o)) {
$multi = true;
}
+
+ $r = q("select mid, title from item where parent_mid = '%s' and author_xchan = '%s'",
+ dbesc($item['mid']),
+ dbesc($post['author_xchan'])
+ );
+
+ // prevent any duplicate votes by same author for oneOf and duplicate votes with same author and same answer for anyOf
+
+ if ($r) {
+ if ($multi) {
+ foreach ($r as $rv) {
+ if ($rv['title'] === $content && $rv['mid'] !== $mid) {
+ return false;
+ }
+ }
+ }
+ else {
+ foreach ($r as $rv) {
+ if ($rv['mid'] !== $mid) {
+ return false;
+ }
+ }
+ }
+ }
+
$answer_found = false;
$found = false;
if ($multi) {
@@ -1888,17 +1953,22 @@ class Activity {
}
}
- $a = self::decode_attachment($act->obj);
- if($a) {
- $s['attach'] = $a;
- }
+ }
+
+ $a = self::decode_attachment($act->obj);
+ if ($a) {
+ $s['attach'] = $a;
+ }
+
+ $a = self::decode_iconfig($act->obj);
+ if ($a) {
+ $s['iconfig'] = $a;
}
if($act->obj['type'] === 'Note' && $s['attach']) {
$s['body'] .= self::bb_attach($s['attach'],$s['body']);
}
-
if ($act->obj['type'] === 'Question' && in_array($act->type,['Create','Update'])) {
if ($act->obj['endTime']) {
$s['comments_closed'] = datetime_convert('UTC','UTC', $act->obj['endTime']);
diff --git a/Zotlabs/Lib/NativeWikiPage.php b/Zotlabs/Lib/NativeWikiPage.php
index dddd26af3..d84cc50a8 100644
--- a/Zotlabs/Lib/NativeWikiPage.php
+++ b/Zotlabs/Lib/NativeWikiPage.php
@@ -530,8 +530,11 @@ class NativeWikiPage {
foreach ($match[1] as $m) {
// TODO: Why do we need to double urlencode for this to work?
//$pageURLs[] = urlencode(urlencode(escape_tags($m)));
- $pageURLs[] = Zlib\NativeWiki::name_encode(escape_tags($m));
- $pages[] = $m;
+ $titleUri = explode('|',$m);
+ $page = $titleUri[0] ?? '';
+ $title = $titleUri[1] ?? $page;
+ $pageURLs[] = Zlib\NativeWiki::name_encode(escape_tags($page));
+ $pages[] = $title;
}
$idx = 0;
while(strpos($s,'[[') !== false) {
diff --git a/Zotlabs/Module/Apschema.php b/Zotlabs/Module/Apschema.php
index 756057a8a..6b0325d44 100644
--- a/Zotlabs/Module/Apschema.php
+++ b/Zotlabs/Module/Apschema.php
@@ -29,7 +29,10 @@ class Apschema extends \Zotlabs\Web\Controller {
'emojiReaction' => 'zot:emojiReaction',
'expires' => 'zot:expires',
'directMessage' => 'zot:directMessage',
-
+ 'schema' => 'http://schema.org#',
+ 'PropertyValue' => 'schema:PropertyValue',
+ 'value' => 'schema:value',
+
'magicEnv' => [
'@id' => 'zot:magicEnv',
'@type' => '@id'
diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php
index 4b866eace..86b5c1c7a 100644
--- a/Zotlabs/Module/Item.php
+++ b/Zotlabs/Module/Item.php
@@ -271,7 +271,9 @@ class Item extends Controller {
$consensus = intval($_REQUEST['consensus']);
$nocomment = intval($_REQUEST['nocomment']);
-
+
+ $is_poll = ((trim($_REQUEST['poll_answers'][0]) != '' && trim($_REQUEST['poll_answers'][1]) != '') ? true : false);
+
// 'origin' (if non-zero) indicates that this network is where the message originated,
// for the purpose of relaying comments to other conversation members.
// If using the API from a device (leaf node) you must set origin to 1 (default) or leave unset.
@@ -920,7 +922,21 @@ class Item extends Controller {
$mid = z_root() . '/item/' . $uuid;
}
- $obj = $this->extract_poll_data($body,[ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]);
+
+ if($is_poll) {
+ $poll = [
+ 'question' => $body,
+ 'answers' => $_REQUEST['poll_answers'],
+ 'multiple_answers' => $_REQUEST['poll_multiple_answers'],
+ 'expire_value' => $_REQUEST['poll_expire_value'],
+ 'expire_unit' => $_REQUEST['poll_expire_unit']
+ ];
+ $obj = $this->extract_poll_data($poll, [ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]);
+ }
+ else {
+ $obj = $this->extract_bb_poll_data($body,[ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]);
+ }
+
if ($obj) {
$obj['url'] = $mid;
$obj['attributedTo'] = channel_url($channel);
@@ -1397,7 +1413,7 @@ class Item extends Controller {
return $ret;
}
- function extract_poll_data(&$body,$item) {
+ function extract_bb_poll_data(&$body,$item) {
$multiple = false;
@@ -1457,5 +1473,44 @@ class Item extends Controller {
}
+ function extract_poll_data($poll, $item) {
+
+ $multiple = intval($poll['multiple_answers']);
+ $expire_value = intval($poll['expire_value']);
+ $expire_unit = $poll['expire_unit'];
+ $question = $poll['question'];
+ $answers = $poll['answers'];
+
+ $obj = [];
+ $ptr = [];
+ $obj['type'] = 'Question';
+ $obj['content'] = bbcode($question);
+
+ foreach($answers as $answer) {
+ if(trim($answer))
+ $ptr[] = [ 'name' => escape_tags($answer), 'type' => 'Note', 'replies' => [ 'type' => 'Collection', 'totalItems' => 0 ]];
+ }
+
+ if($multiple) {
+ $obj['anyOf'] = $ptr;
+ }
+ else {
+ $obj['oneOf'] = $ptr;
+ }
+
+ $obj['endTime'] = datetime_convert(date_default_timezone_get(), 'UTC', 'now + ' . $expire_value . ' ' . $expire_unit, ATOM_TIME);
+
+ if ($item['item_private']) {
+ $obj['to'] = Activity::map_acl($item);
+ }
+ else {
+ $obj['to'] = [ ACTIVITY_PUBLIC_INBOX ];
+ }
+
+ return $obj;
+
+ }
+
+
}