From b033597ada02ef045bc9fbdb2237f81935b73e47 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 11 Nov 2019 21:30:38 +0100 Subject: sse notifications --- Zotlabs/Lib/Enotify.php | 136 ++++++++++++++++++++++++++++++++++++++++++++- Zotlabs/Lib/ThreadItem.php | 5 +- 2 files changed, 136 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 92a488f67..de2bfba24 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -550,6 +550,11 @@ class Enotify { if ((\App::$language === 'en' || (! \App::$language)) && strpos($msg,', ')) $msg = substr($msg,strpos($msg,', ')+1); + $datarray['id'] = $notify_id; + $datarray['msg'] = $msg; + + call_hooks('enotify_store_end', $datarray); + $r = q("update notify set msg = '%s' where id = %d and uid = %d", dbesc($msg), intval($notify_id), @@ -838,7 +843,7 @@ class Enotify { 'addr' => (($item[$who]['xchan_addr']) ? $item[$who]['xchan_addr'] : $item[$who]['xchan_url']), 'url' => $item[$who]['xchan_url'], 'photo' => $item[$who]['xchan_photo_s'], - 'when' => relative_date(($edit)? $item['edited'] : $item['created']), + 'when' => (($edit) ? datetime_convert('UTC', date_default_timezone_get(), $item['edited']) : datetime_convert('UTC', date_default_timezone_get(), $item['created'])), 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'), 'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'notify_id' => 'undefined', @@ -846,7 +851,7 @@ class Enotify { 'message' => strip_tags(bbcode($itemem_text)), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], - 'uid' => local_channel(), + 'uid' => $item['uid'], 'display' => true ); @@ -858,4 +863,131 @@ class Enotify { return $x; } + static public function format_notify($tt) { + + $message = trim(strip_tags(bbcode($tt['msg']))); + + if(strpos($message, $tt['xname']) === 0) + $message = substr($message, strlen($tt['xname']) + 1); + + $mid = basename($tt['link']); + $mid = ((strpos($mid, 'b64.') === 0) ? @base64url_decode(substr($mid, 4)) : $mid); + + if(in_array($tt['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { + // we need the thread parent + $r = q("select thr_parent from item where mid = '%s' and uid = %d limit 1", + dbesc($mid), + intval(local_channel()) + ); + $b64mid = ((strpos($r[0]['thr_parent'], 'b64.') === 0) ? $r[0]['thr_parent'] : 'b64.' . base64url_encode($r[0]['thr_parent'])); + } + else { + $b64mid = ((strpos($mid, 'b64.') === 0) ? $mid : 'b64.' . base64url_encode($mid)); + } + + $x = [ + 'notify_link' => z_root() . '/notify/view/' . $tt['id'], + 'name' => $tt['xname'], + 'url' => $tt['url'], + 'photo' => $tt['photo'], + 'when' => datetime_convert('UTC', date_default_timezone_get(), $tt['created']), + 'hclass' => (($tt['seen']) ? 'notify-seen' : 'notify-unseen'), + 'b64mid' => (($tt['otype'] == 'item') ? $b64mid : 'undefined'), + 'notify_id' => (($tt['otype'] == 'item') ? $tt['id'] : 'undefined'), + 'message' => $message + ]; + + return $x; + + } + + static public function format_intros($rr) { + + $x = [ + 'notify_link' => z_root() . '/connections/ifpending', + 'name' => $rr['xchan_name'], + 'addr' => $rr['xchan_addr'], + 'url' => $rr['xchan_url'], + 'photo' => $rr['xchan_photo_s'], + 'when' => datetime_convert('UTC', date_default_timezone_get(), $rr['abook_created']), + 'hclass' => ('notify-unseen'), + 'message' => t('added your channel') + ]; + + return $x; + + } + + static public function format_files($rr) { + + $x = [ + 'notify_link' => z_root() . '/sharedwithme', + 'name' => $rr['author']['xchan_name'], + 'addr' => $rr['author']['xchan_addr'], + 'url' => $rr['author']['xchan_url'], + 'photo' => $rr['author']['xchan_photo_s'], + 'when' => datetime_convert('UTC', date_default_timezone_get(), $rr['created']), + 'hclass' => ('notify-unseen'), + 'message' => t('shared a file with you') + ]; + + return $x; + + } + + static public function format_mail($rr) { + + $x = [ + 'notify_link' => z_root() . '/mail/' . $rr['id'], + 'name' => $rr['xchan_name'], + 'addr' => $rr['xchan_addr'], + 'url' => $rr['xchan_url'], + 'photo' => $rr['xchan_photo_s'], + 'when' => datetime_convert('UTC', date_default_timezone_get(), $rr['created']), + 'hclass' => (intval($rr['mail_seen']) ? 'notify-seen' : 'notify-unseen'), + 'message' => t('sent you a private message'), + ]; + + return $x; + + } + + static public function format_all_events($rr) { + + $bd_format = t('g A l F d') ; // 8 AM Friday January 18 + $strt = datetime_convert('UTC', (($rr['adjust']) ? date_default_timezone_get() : 'UTC'), $rr['dtstart']); + $today = ((substr($strt, 0, 10) === datetime_convert('UTC', date_default_timezone_get(), 'now', 'Y-m-d')) ? true : false); + $when = day_translate(datetime_convert('UTC', (($rr['adjust']) ? date_default_timezone_get() : 'UTC'), $rr['dtstart'], $bd_format)) . (($today) ? ' ' . t('[today]') : ''); + + $x = [ + 'notify_link' => z_root() . '/cdav/calendar/' . $rr['event_hash'], + 'name' => $rr['xchan_name'], + 'addr' => $rr['xchan_addr'], + 'url' => $rr['xchan_url'], + 'photo' => $rr['xchan_photo_s'], + 'when' => $when, + 'hclass' => ('notify-unseen'), + 'message' => t('posted an event') + ]; + + return $x; + + } + + static public function format_register($rr) { + + $x = [ + 'notify_link' => z_root() . '/admin/accounts', + 'name' => $rr['account_email'], + 'addr' => $rr['account_email'], + 'url' => '', + 'photo' => z_root() . '/' . get_default_profile_photo(48), + 'when' => datetime_convert('UTC', date_default_timezone_get(),$rr['account_created']), + 'hclass' => ('notify-unseen'), + 'message' => t('requires approval') + ]; + + return $x; + + } } diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 5e4600df2..174af7f0e 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -369,7 +369,7 @@ class ThreadItem { 'folders' => $body['folders'], 'text' => strip_tags($body['html']), 'id' => $this->get_id(), - 'mid' => $item['mid'], + 'mid' => 'b64.' . base64url_encode($item['mid']), 'parent' => $item['parent'], 'author_id' => (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']), 'isevent' => $isevent, @@ -467,10 +467,9 @@ class ThreadItem { 'previewing' => ($conv->is_preview() ? true : false ), 'preview_lbl' => t('This is an unsaved preview'), 'wait' => t('Please wait'), - 'submid' => str_replace(['+','='], ['',''], base64_encode($item['mid'])), 'thread_level' => $thread_level, 'settings' => $settings, - 'thr_parent' => (($item['parent_mid'] != $item['thr_parent']) ? $item['thr_parent'] : '') + 'thr_parent' => (($item['parent_mid'] != $item['thr_parent']) ? 'b64.' . base64url_encode($item['thr_parent']) : '') ); $arr = array('item' => $item, 'output' => $tmp_item); -- cgit v1.2.3 From 3009c88d246ddcafabf1965f88c5ebd8fe1717fd Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 15 Nov 2019 09:43:39 +0000 Subject: AP fixes --- Zotlabs/Lib/Activity.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index e41e165b1..08a8b8d03 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -609,9 +609,15 @@ class Activity { } if($i['id'] != $i['parent']) { - $ret['inReplyTo'] = ((strpos($i['thr_parent'],'http') === 0) ? $i['thr_parent'] : z_root() . '/item/' . urlencode($i['thr_parent'])); $reply = true; + // inReplyTo needs to be set in the activity for followup actiions (Like, Dislike, Attend, Announce, etc.), + // but *not* for comments, where it should only be present in the object + + if (! in_array($ret['type'],[ 'Create','Update' ])) { + $ret['inReplyTo'] = ((strpos($i['thr_parent'],'http') === 0) ? $i['thr_parent'] : z_root() . '/item/' . urlencode($i['thr_parent'])); + } + if($i['item_private']) { $d = q("select xchan_url, xchan_addr, xchan_name from item left join xchan on xchan_hash = author_xchan where id = %d limit 1", intval($i['parent']) -- cgit v1.2.3 From b62eb665c5ad12ec7bde6bace71a0ddbb6aac28d Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 22 Nov 2019 14:11:26 +0000 Subject: sse: store the item mid plus reactions mids in data-mids and change functions accordingly --- Zotlabs/Lib/Enotify.php | 3 ++- Zotlabs/Lib/ThreadItem.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index de2bfba24..c1a6c9fdc 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -845,7 +845,8 @@ class Enotify { 'photo' => $item[$who]['xchan_photo_s'], 'when' => (($edit) ? datetime_convert('UTC', date_default_timezone_get(), $item['edited']) : datetime_convert('UTC', date_default_timezone_get(), $item['created'])), 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'), - 'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), + 'b64mid' => 'b64.' . base64url_encode($item['mid']), + //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'notify_id' => 'undefined', 'thread_top' => (($item['item_thread_top']) ? true : false), 'message' => strip_tags(bbcode($itemem_text)), diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 174af7f0e..0f59953dc 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -78,7 +78,7 @@ class ThreadItem { */ public function get_template_data($conv_responses, $thread_level=1, $conv_flags = []) { - + $result = array(); $item = $this->get_data(); @@ -356,6 +356,17 @@ class ThreadItem { call_hooks('dropdown_extras',$dropdown_extras_arr); $dropdown_extras = $dropdown_extras_arr['dropdown_extras']; + $mids = ['b64.' . base64url_encode($item['mid'])]; + $response_mids = []; + foreach($response_verbs as $v) { + if(isset($conv_responses[$v]['mids'][$item['mid']])) { + $response_mids = array_merge($response_mids, $conv_responses[$v]['mids'][$item['mid']]); + } + } + + $mids = array_merge($mids, $response_mids); + $json_mids = json_encode($mids); + $tmp_item = array( 'template' => $this->get_template(), 'mode' => $mode, @@ -370,6 +381,7 @@ class ThreadItem { 'text' => strip_tags($body['html']), 'id' => $this->get_id(), 'mid' => 'b64.' . base64url_encode($item['mid']), + 'mids' => $json_mids, 'parent' => $item['parent'], 'author_id' => (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']), 'isevent' => $isevent, -- cgit v1.2.3 From 73a0866ac4666e615742884a9eb3464c742f787b Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 22 Nov 2019 20:52:22 +0000 Subject: sse: fix a regression where not all appearances of an notification were looped through and fix format_notify() to not look for the parent item anymore --- Zotlabs/Lib/Enotify.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index c1a6c9fdc..bc2710ee1 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -872,19 +872,8 @@ class Enotify { $message = substr($message, strlen($tt['xname']) + 1); $mid = basename($tt['link']); - $mid = ((strpos($mid, 'b64.') === 0) ? @base64url_decode(substr($mid, 4)) : $mid); - if(in_array($tt['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { - // we need the thread parent - $r = q("select thr_parent from item where mid = '%s' and uid = %d limit 1", - dbesc($mid), - intval(local_channel()) - ); - $b64mid = ((strpos($r[0]['thr_parent'], 'b64.') === 0) ? $r[0]['thr_parent'] : 'b64.' . base64url_encode($r[0]['thr_parent'])); - } - else { - $b64mid = ((strpos($mid, 'b64.') === 0) ? $mid : 'b64.' . base64url_encode($mid)); - } + $b64mid = ((strpos($mid, 'b64.') === 0) ? $mid : 'b64.' . base64url_encode($mid)); $x = [ 'notify_link' => z_root() . '/notify/view/' . $tt['id'], -- cgit v1.2.3 From 901785663edc7045c66d9393432a18bb376436bb Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 25 Nov 2019 21:50:02 +0100 Subject: Fix once cached embedded content is used and stored forever --- Zotlabs/Lib/Cache.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index cea075659..878201a42 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -11,8 +11,10 @@ class Cache { $hash = hash('whirlpool',$key); - $r = q("SELECT v FROM cache WHERE k = '%s' limit 1", - dbesc($hash) + $r = q("SELECT v FROM cache WHERE k = '%s' AND updated > %s - INTERVAL %s LIMIT 1", + dbesc($hash), + db_utcnow(), + db_quoteinterval(get_config('system','object_cache_days', '30') . ' DAY') ); if ($r) @@ -40,12 +42,5 @@ class Cache { dbesc(datetime_convert())); } } - - - public static function clear() { - q("DELETE FROM cache WHERE updated < '%s'", - dbesc(datetime_convert('UTC','UTC',"now - 30 days"))); - } - } -- cgit v1.2.3 From c86b35da701674510a97ccc21e46581bd864cc31 Mon Sep 17 00:00:00 2001 From: "DM42.Net Hubzilla Development" Date: Thu, 28 Nov 2019 00:27:12 -0500 Subject: Move auto_save_draft to header from thread comment --- Zotlabs/Lib/ThreadItem.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 0f59953dc..32cd52751 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -789,8 +789,6 @@ class ThreadItem { call_hooks('comment_buttons',$arr); $comment_buttons = $arr['comment_buttons']; - $feature_auto_save_draft = ((feature_enabled($conv->get_profile_owner(), 'auto_save_draft')) ? "true" : "false"); - $comment_box = replace_macros($template,array( '$return_path' => '', '$threaded' => $this->is_threaded(), @@ -825,8 +823,7 @@ class ThreadItem { '$anoncomments' => ((($conv->get_mode() === 'channel' || $conv->get_mode() === 'display') && perm_is_allowed($conv->get_profile_owner(),'','post_comments')) ? true : false), '$anonname' => [ 'anonname', t('Your full name (required)') ], '$anonmail' => [ 'anonmail', t('Your email address (required)') ], - '$anonurl' => [ 'anonurl', t('Your website URL (optional)') ], - '$auto_save_draft' => $feature_auto_save_draft + '$anonurl' => [ 'anonurl', t('Your website URL (optional)') ] )); return $comment_box; -- cgit v1.2.3 From 21b398252aaf28d9ff8045fbe3e9fcb162a6f447 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 4 Dec 2019 03:44:24 +0100 Subject: Add content pinning support --- Zotlabs/Lib/ThreadItem.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 32cd52751..301ce1a18 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -95,7 +95,7 @@ class ThreadItem { $total_children = $this->count_descendants(); $unseen_comments = (($item['real_uid']) ? 0 : $this->count_unseen_descendants()); - $conv = $this->get_conversation(); + $conv = $this->get_conversation(); $observer = $conv->get_observer(); $lock = (((intval($item['item_private'])) || (($item['uid'] == local_channel()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) @@ -356,7 +356,8 @@ class ThreadItem { call_hooks('dropdown_extras',$dropdown_extras_arr); $dropdown_extras = $dropdown_extras_arr['dropdown_extras']; - $mids = ['b64.' . base64url_encode($item['mid'])]; + $midb64 = 'b64.' . base64url_encode($item['mid']); + $mids = [ $midb64 ]; $response_mids = []; foreach($response_verbs as $v) { if(isset($conv_responses[$v]['mids'][$item['mid']])) { @@ -367,6 +368,11 @@ class ThreadItem { $mids = array_merge($mids, $response_mids); $json_mids = json_encode($mids); + // Pinned item processing + $allowed_type = (in_array($item['item_type'], get_config('system', 'pin_types', [ ITEM_TYPE_POST ])) ? true : false); + $pinned_items = ($allowed_type ? get_pconfig($item['uid'], 'pinned', $item['item_type'], []) : []); + $pinned = ((!empty($pinned_items) && in_array($midb64, $pinned_items)) ? true : false); + $tmp_item = array( 'template' => $this->get_template(), 'mode' => $mode, @@ -380,7 +386,7 @@ class ThreadItem { 'folders' => $body['folders'], 'text' => strip_tags($body['html']), 'id' => $this->get_id(), - 'mid' => 'b64.' . base64url_encode($item['mid']), + 'mid' => $midb64, 'mids' => $json_mids, 'parent' => $item['parent'], 'author_id' => (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']), @@ -449,6 +455,9 @@ class ThreadItem { 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts') && ($item['item_type'] == ITEM_TYPE_POST)) ? $star : ''), 'tagger' => ((feature_enabled($conv->get_profile_owner(),'commtag')) ? $tagger : ''), 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing') && ($item['item_type'] == ITEM_TYPE_POST)) ? $filer : ''), + 'pinned' => ($pinned ? t('Pinned post') : ''), + 'pinnable' => (($this->is_toplevel() && local_channel() && $item['owner_xchan'] == $observer['xchan_hash'] && $allowed_type && $item['item_private'] == 0) ? '1' : ''), + 'pinme' => ($pinned ? t('Unpin from the top') : t('Pin to the top')), 'bookmark' => (($conv->get_profile_owner() == local_channel() && local_channel() && $has_bookmarks) ? t('Save Bookmarks') : ''), 'addtocal' => (($has_event) ? t('Add to Calendar') : ''), 'drop' => $drop, @@ -874,7 +883,4 @@ class ThreadItem { return $this->visiting; } - - - } -- cgit v1.2.3 From 88ebbd90d8925a74029a32f57ec581d2b3ba64ed Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 9 Dec 2019 19:43:01 -0800 Subject: missing translation "%d unseen" --- Zotlabs/Lib/ThreadItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 301ce1a18..caceac7ef 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -346,7 +346,7 @@ class ThreadItem { $viewthread = z_root() . '/channel/' . $owner_address . '?f=&mid=' . urlencode(gen_link_id($item['mid'])); $comment_count_txt = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); - $list_unseen_txt = (($unseen_comments) ? sprintf('%d unseen',$unseen_comments) : ''); + $list_unseen_txt = (($unseen_comments) ? sprintf( t('%d unseen'),$unseen_comments) : ''); $children = $this->get_children(); -- cgit v1.2.3 From 41ce2da080d72dbfd2c47a3973fe3c43672adb4d Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sun, 5 Jan 2020 11:49:36 +0100 Subject: Add age choice on cached item retrieve --- Zotlabs/Lib/Cache.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index 878201a42..bb7bbbff0 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -7,14 +7,23 @@ namespace Zotlabs\Lib; */ class Cache { - public static function get($key) { + + /** + * @brief Returns cached content + * + * @param string $key + * @param string $age in SQL format, default is '30 DAY' + * @return string + * / + + public static function get($key, $age = '') { $hash = hash('whirlpool',$key); $r = q("SELECT v FROM cache WHERE k = '%s' AND updated > %s - INTERVAL %s LIMIT 1", dbesc($hash), db_utcnow(), - db_quoteinterval(get_config('system','object_cache_days', '30') . ' DAY') + db_quoteinterval(($age ? $age : get_config('system','object_cache_days', '30') . ' DAY')) ); if ($r) -- cgit v1.2.3 From 908875a052ac76e24af74fc714b350c217de42b4 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 6 Jan 2020 20:40:18 +0100 Subject: Update Cache.php --- Zotlabs/Lib/Cache.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index bb7bbbff0..a5052a183 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -14,7 +14,7 @@ class Cache { * @param string $key * @param string $age in SQL format, default is '30 DAY' * @return string - * / + */ public static function get($key, $age = '') { @@ -52,4 +52,3 @@ class Cache { } } } - -- cgit v1.2.3 From d3cbbe029c1f19a77ac0c278f735d81b9dd3a3ec Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Jan 2020 22:41:28 -0800 Subject: rework activitystreams events - send invite/event activities instead of create/event. Also a first pass at creating a Zap export file from Hubzilla. Much more work is needed before this is functional. --- Zotlabs/Lib/Activity.php | 35 +++++++++++++++++++++++------------ Zotlabs/Lib/ActivityStreams.php | 6 ++++++ 2 files changed, 29 insertions(+), 12 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 08a8b8d03..a0956c501 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -611,10 +611,10 @@ class Activity { if($i['id'] != $i['parent']) { $reply = true; - // inReplyTo needs to be set in the activity for followup actiions (Like, Dislike, Attend, Announce, etc.), - // but *not* for comments, where it should only be present in the object - - if (! in_array($ret['type'],[ 'Create','Update' ])) { + // inReplyTo needs to be set in the activity for followup actions (Like, Dislike, Announce, etc.), + // but *not* for comments and RSVPs, where it should only be present in the object + + if (! in_array($ret['type'],[ 'Create','Update','Accept','Reject','TentativeAccept','TentativeReject' ])) { $ret['inReplyTo'] = ((strpos($i['thr_parent'],'http') === 0) ? $i['thr_parent'] : z_root() . '/item/' . urlencode($i['thr_parent'])); } @@ -672,6 +672,9 @@ class Activity { return []; } + if(array_path_exists('object/type',$ret) && $ret['object']['type'] === 'Event' && $ret['type'] === 'Create') { + $ret['type'] = 'Invite'; + } if($i['target']) { if(! is_array($i['target'])) { @@ -1664,15 +1667,23 @@ class Activity { if($act->type === 'Dislike') { $content['content'] = sprintf( t('Doesn\'t like %1$s\'s %2$s'),$mention,$act->obj['type']) . "\n\n" . $content['content']; } - if($act->type === 'Accept' && $act->obj['type'] === 'Event' ) { - $content['content'] = sprintf( t('Will attend %1$s\'s %2$s'),$mention,$act->obj['type']) . "\n\n" . $content['content']; - } - if($act->type === 'Reject' && $act->obj['type'] === 'Event' ) { - $content['content'] = sprintf( t('Will not attend %1$s\'s %2$s'),$mention,$act->obj['type']) . "\n\n" . $content['content']; - } - if($act->type === 'TentativeAccept' && $act->obj['type'] === 'Event' ) { - $content['content'] = sprintf( t('May attend %1$s\'s %2$s'),$mention,$act->obj['type']) . "\n\n" . $content['content']; + + // handle event RSVPs + if (($act->obj['type'] === 'Event') || ($act->obj['type'] === 'Invite' && array_path_exists('object/type',$act->obj) && $act->obj['object']['type'] === 'Event')) { + if ($act->type === 'Accept') { + $content['content'] = sprintf( t('Will attend %s\'s event'),$mention) . EOL . EOL . $content['content']; + } + if ($act->type === 'Reject') { + $content['content'] = sprintf( t('Will not attend %s\'s event'),$mention) . EOL . EOL . $content['content']; + } + if ($act->type === 'TentativeAccept') { + $content['content'] = sprintf( t('May attend %s\'s event'),$mention) . EOL . EOL . $content['content']; + } + if ($act->type === 'TentativeReject') { + $content['content'] = sprintf( t('May not attend %s\'s event'),$mention) . EOL . EOL . $content['content']; + } } + if($act->type === 'Announce') { $content['content'] = sprintf( t('🔁 Repeated %1$s\'s %2$s'), $mention, $act->obj['type']); } diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index 006744aff..d8bd72943 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -101,7 +101,13 @@ class ActivityStreams { $this->actor = $this->get_actor('attributedTo',$this->obj); } } + + // fetch recursive or embedded activities + if ($this->obj && is_array($this->obj) && array_key_exists('object',$this->obj)) { + $this->obj['object'] = $this->get_compound_property($this->obj['object']); + } + if($this->obj && is_array($this->obj) && $this->obj['actor']) $this->obj['actor'] = $this->get_actor('actor',$this->obj); if($this->tgt && is_array($this->tgt) && $this->tgt['actor']) -- cgit v1.2.3 From 2a287e6def5ab54037222c963ab0875faf62fc1a Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 14 Jan 2020 13:29:45 -0800 Subject: event compatibility work --- Zotlabs/Lib/Activity.php | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index a0956c501..a99bb36e4 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -168,6 +168,10 @@ class Activity { if($r) { xchan_query($r,true); $r = fetch_post_tags($r,true); + if ($r[0]['verb'] === 'Create' && $r[0]['obj_type'] === ACTIVITY_OBJ_EVENT) { + $r[0]['verb'] = 'Invite'; + return self::encode_activity($r[0]); + } return self::encode_item($r[0]); } } @@ -220,7 +224,7 @@ class Activity { 'startTime' => (($ev['adjust']) ? datetime_convert($ev['timezone'],'UTC',$ev['dtstart'], ATOM_TIME) : datetime_convert('UTC','UTC',$ev['dtstart'],'Y-m-d\\TH:i:s-00:00')), 'content' => bbcode($ev['description'], [ 'cache' => true ]), 'location' => [ 'type' => 'Place', 'content' => bbcode($ev['location'], [ 'cache' => true ]) ], - 'source' => [ 'content' => format_event_bbcode($ev), 'mediaType' => 'text/bbcode' ], + 'source' => [ 'content' => format_event_bbcode($ev,true), 'mediaType' => 'text/bbcode' ], 'actor' => $actor, ]; if(! $ev['nofinish']) { @@ -825,7 +829,8 @@ class Activity { 'http://activitystrea.ms/schema/1.0/unfollow' => 'Unfollow', 'http://purl.org/zot/activity/attendyes' => 'Accept', 'http://purl.org/zot/activity/attendno' => 'Reject', - 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept' + 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept', + 'Invite' => 'Invite', ]; call_hooks('activity_mapper',$acts); @@ -871,7 +876,8 @@ class Activity { 'http://activitystrea.ms/schema/1.0/unfollow' => 'Unfollow', 'http://purl.org/zot/activity/attendyes' => 'Accept', 'http://purl.org/zot/activity/attendno' => 'Reject', - 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept' + 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept', + 'Invite' => 'Invite', ]; call_hooks('activity_decode_mapper',$acts); @@ -905,6 +911,7 @@ class Activity { 'http://purl.org/zot/activity/thing' => 'Object', 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', + 'Invite' => 'Invite', ]; @@ -944,7 +951,7 @@ class Activity { 'http://purl.org/zot/activity/thing' => 'Object', 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', - + 'Invite' => 'Invite', ]; call_hooks('activity_obj_mapper',$objs); @@ -1714,28 +1721,42 @@ class Activity { $s['obj_type'] = ACTIVITY_OBJ_COMMENT; } + $eventptr = null; + + if ($act->obj['type'] === 'Invite' && array_path_exists('object/type',$act->obj) && $act->obj['object']['type'] === 'Event') { + $eventptr = $act->obj['object']; + $s['mid'] = $s['parent_mid'] = $act->obj['id']; + } + if($act->obj['type'] === 'Event') { + if ($act->type === 'Invite') { + $s['mid'] = $s['parent_mid'] = $act->id; + } + $eventptr = $act->obj; + } + + if ($eventptr) { $s['obj'] = []; - $s['obj']['asld'] = $act->obj; + $s['obj']['asld'] = $eventptr; $s['obj']['type'] = ACTIVITY_OBJ_EVENT; - $s['obj']['id'] = $act->obj['id']; - $s['obj']['title'] = $act->obj['name']; + $s['obj']['id'] = $eventptr['id']; + $s['obj']['title'] = $eventptr['name']; if(strpos($act->obj['startTime'],'Z')) $s['obj']['adjust'] = true; else $s['obj']['adjust'] = false; - $s['obj']['dtstart'] = datetime_convert('UTC','UTC',$act->obj['startTime']); + $s['obj']['dtstart'] = datetime_convert('UTC','UTC',$eventptr['startTime']); if($act->obj['endTime']) - $s['obj']['dtend'] = datetime_convert('UTC','UTC',$act->obj['endTime']); + $s['obj']['dtend'] = datetime_convert('UTC','UTC',$eventptr['endTime']); else $s['obj']['nofinish'] = true; - $s['obj']['description'] = $act->obj['content']; + $s['obj']['description'] = $eventptr['content']; - if(array_path_exists('location/content',$act->obj)) - $s['obj']['location'] = $act->obj['location']['content']; + if(array_path_exists('location/content',$eventptr)) + $s['obj']['location'] = $eventptr['location']['content']; } else { -- cgit v1.2.3 From 2a0a06d74aa1e51b0e50459f90167ab35ba1411b Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 15 Jan 2020 21:43:47 +0000 Subject: some work on zot6 DMs --- Zotlabs/Lib/Activity.php | 8 +++++++- Zotlabs/Lib/Libzot.php | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index a99bb36e4..43315a87f 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1989,9 +1989,15 @@ class Activity { $s['plink'] = $s['mid']; } - if($act->recips && (! in_array(ACTIVITY_PUBLIC_INBOX,$act->recips))) + if ($act->recips && (! in_array(ACTIVITY_PUBLIC_INBOX,$act->recips))) $s['item_private'] = 1; + if (is_array($act->obj)) { + if (array_key_exists('directMessage',$act->obj) && intval($act->obj['directMessage'])) { + $s['item_private'] = 2; + } + } + set_iconfig($s,'activitypub','recips',$act->raw_recips); $parent = (($s['parent_mid'] && $s['parent_mid'] === $s['mid']) ? true : false); diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 100d45c05..ad00aa97a 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1220,8 +1220,8 @@ class Libzot { $arr['owner_xchan'] = $env['sender']; } - if($private) { - $arr['item_private'] = true; + if ($private && (! intval($arr['item_private']))) { + $arr['item_private'] = 1; } if ($arr['mid'] === $arr['parent_mid']) { -- cgit v1.2.3 From bfae86bdb6d18f4238fe114485e24947ad7c7d75 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Jan 2020 13:17:37 +0000 Subject: more bdi tags --- Zotlabs/Lib/Enotify.php | 10 +++++----- Zotlabs/Lib/ThreadItem.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index bc2710ee1..8834eedca 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -803,18 +803,18 @@ class Enotify { localize_item($item); if($item['shortlocalize']) { - $itemem_text = $item['shortlocalize']; + $itemem_text = strip_tags($item['shortlocalize']); } elseif($item['localize']) { - $itemem_text = $item['localize']; + $itemem_text = strip_tags($item['localize']); } else { $itemem_text = (($item['item_thread_top']) ? t('created a new post') - : sprintf( t('commented on %s\'s post'), $item['owner']['xchan_name'])); + : sprintf( t('commented on %s\'s post'), '' . strip_tags($item['owner']['xchan_name']) . '')); if($item['verb'] === ACTIVITY_SHARE) { - $itemem_text = sprintf( t('repeated %s\'s post'), $item['author']['xchan_name']); + $itemem_text = sprintf( t('repeated %s\'s post'), '' . strip_tags($item['author']['xchan_name']) . ''); } } @@ -849,7 +849,7 @@ class Enotify { //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'notify_id' => 'undefined', 'thread_top' => (($item['item_thread_top']) ? true : false), - 'message' => strip_tags(bbcode($itemem_text)), + 'message' => $itemem_text, // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], 'uid' => $item['uid'], diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index caceac7ef..ef7b4dbf2 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -377,7 +377,7 @@ class ThreadItem { 'template' => $this->get_template(), 'mode' => $mode, 'item_type' => intval($item['item_type']), - 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), + //'type' => implode("",array_slice(explode("/",$item['verb']),-1)), 'body' => $body['html'], 'tags' => $body['tags'], 'categories' => $body['categories'], @@ -414,7 +414,7 @@ class ThreadItem { 'sparkle' => $sparkle, 'title' => $item['title'], 'title_tosource' => get_pconfig($conv->get_profile_owner(),'system','title_tosource'), - 'ago' => relative_date($item['created']), + //'ago' => relative_date($item['created']), 'app' => $item['app'], 'str_app' => sprintf( t('from %s'), $item['app']), 'isotime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'c'), -- cgit v1.2.3 From 7404a8ec1a0980fa3448ca6b05e410ea36c6a5f2 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Jan 2020 14:19:31 +0000 Subject: implement bdi tags via bbcode where possible --- Zotlabs/Lib/Enotify.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 8834eedca..db80e9edd 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -803,18 +803,18 @@ class Enotify { localize_item($item); if($item['shortlocalize']) { - $itemem_text = strip_tags($item['shortlocalize']); + $itemem_text = $item['shortlocalize']; } elseif($item['localize']) { - $itemem_text = strip_tags($item['localize']); + $itemem_text = $item['localize']; } else { $itemem_text = (($item['item_thread_top']) ? t('created a new post') - : sprintf( t('commented on %s\'s post'), '' . strip_tags($item['owner']['xchan_name']) . '')); + : sprintf( t('commented on %s\'s post'), '[bdi]' . $item['owner']['xchan_name'] . '[/bdi]')); if($item['verb'] === ACTIVITY_SHARE) { - $itemem_text = sprintf( t('repeated %s\'s post'), '' . strip_tags($item['author']['xchan_name']) . ''); + $itemem_text = sprintf( t('repeated %s\'s post'), '[bdi]' . $item['author']['xchan_name'] . '[/bdi]'); } } @@ -849,7 +849,7 @@ class Enotify { //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'notify_id' => 'undefined', 'thread_top' => (($item['item_thread_top']) ? true : false), - 'message' => $itemem_text, + 'message' => bbcode(strip_tags($itemem_text)), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], 'uid' => $item['uid'], -- cgit v1.2.3 From 9eeccc087dbba93d5d67c242666fe257cc35f3ee Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Jan 2020 14:23:23 +0000 Subject: move mail frontend to addons and remove mail app from system apps --- Zotlabs/Lib/Apps.php | 1 - 1 file changed, 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 69996b49d..9d60e9eae 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -74,7 +74,6 @@ class Apps { 'Directory', 'Search', 'Help', - 'Mail', 'Profile Photo' ]); -- cgit v1.2.3 From 570d84c031d9cdf0e16aa79bc4a7a111345cc3f3 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Jan 2020 16:04:40 +0000 Subject: fix shortlocalize --- Zotlabs/Lib/Enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index db80e9edd..f6f8ad0cb 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -849,7 +849,7 @@ class Enotify { //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'notify_id' => 'undefined', 'thread_top' => (($item['item_thread_top']) ? true : false), - 'message' => bbcode(strip_tags($itemem_text)), + 'message' => bbcode(escape_tags($itemem_text)), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], 'uid' => $item['uid'], -- cgit v1.2.3 From bbfe71b0c68579d3a0cc955c12b314e702924940 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Jan 2020 20:46:52 +0000 Subject: the address or URL as linktitle should be sufficient --- Zotlabs/Lib/ThreadItem.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index ef7b4dbf2..2386a1f0d 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -395,8 +395,8 @@ class ThreadItem { 'consensus' => $consensus, 'conlabels' => $conlabels, 'canvote' => $canvote, - 'linktitle' => sprintf( t('View %s\'s profile - %s'), $profile_name, (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url'])), - 'olinktitle' => sprintf( t('View %s\'s profile - %s'), $this->get_owner_name(), (($item['owner']['xchan_addr']) ? $item['owner']['xchan_addr'] : $item['owner']['xchan_url'])), + 'linktitle' => (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']), + 'olinktitle' => (($item['owner']['xchan_addr']) ? $item['owner']['xchan_addr'] : $item['owner']['xchan_url']), 'llink' => $item['llink'], 'viewthread' => $viewthread, 'to' => t('to'), -- cgit v1.2.3 From 1712eceaf95e5e57d8f5866cb1f6100a0acd28b6 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 26 Jan 2020 15:08:55 +0000 Subject: port Lib/Connect and Module/Follow from zap. Connect with new connections via zot6 --- Zotlabs/Lib/AccessList.php | 411 +++++++++++++++++++++++++++++++++++++++++++++ Zotlabs/Lib/Connect.php | 315 ++++++++++++++++++++++++++++++++++ 2 files changed, 726 insertions(+) create mode 100644 Zotlabs/Lib/AccessList.php create mode 100644 Zotlabs/Lib/Connect.php (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/AccessList.php b/Zotlabs/Lib/AccessList.php new file mode 100644 index 000000000..3c008f8c7 --- /dev/null +++ b/Zotlabs/Lib/AccessList.php @@ -0,0 +1,411 @@ +may apply to this list and any future members. If this is not what you intended, please create another list with a different name.') . EOL); + } + return true; + } + + $hash = new_uuid(); + + $r = q("INSERT INTO pgrp ( hash, uid, visible, gname ) + VALUES( '%s', %d, %d, '%s' ) ", + dbesc($hash), + intval($uid), + intval($public), + dbesc($name) + ); + $ret = $r; + } + + Libsync::build_sync_packet($uid,null,true); + return $ret; + } + + + static function remove($uid,$name) { + $ret = false; + if ($uid && $name) { + $r = q("SELECT id, hash FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1", + intval($uid), + dbesc($name) + ); + if ($r) { + $group_id = $r[0]['id']; + $group_hash = $r[0]['hash']; + } + else { + return false; + } + + // remove group from default posting lists + $r = q("SELECT channel_default_group, channel_allow_gid, channel_deny_gid FROM channel WHERE channel_id = %d LIMIT 1", + intval($uid) + ); + if ($r) { + $user_info = array_shift($r); + $change = false; + + if ($user_info['channel_default_group'] == $group_hash) { + $user_info['channel_default_group'] = ''; + $change = true; + } + if (strpos($user_info['channel_allow_gid'], '<' . $group_hash . '>') !== false) { + $user_info['channel_allow_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_allow_gid']); + $change = true; + } + if (strpos($user_info['channel_deny_gid'], '<' . $group_hash . '>') !== false) { + $user_info['channel_deny_gid'] = str_replace('<' . $group_hash . '>', '', $user_info['channel_deny_gid']); + $change = true; + } + + if ($change) { + q("UPDATE channel SET channel_default_group = '%s', channel_allow_gid = '%s', channel_deny_gid = '%s' + WHERE channel_id = %d", + intval($user_info['channel_default_group']), + dbesc($user_info['channel_allow_gid']), + dbesc($user_info['channel_deny_gid']), + intval($uid) + ); + } + } + + // remove all members + $r = q("DELETE FROM pgrp_member WHERE uid = %d AND gid = %d ", + intval($uid), + intval($group_id) + ); + + // remove group + $r = q("UPDATE pgrp SET deleted = 1 WHERE uid = %d AND gname = '%s'", + intval($uid), + dbesc($name) + ); + + $ret = $r; + + } + + Libsync::build_sync_packet($uid,null,true); + + return $ret; + } + + // returns the integer id of an access group owned by $uid and named $name + // or false. + + static function byname($uid,$name) { + if (! ($uid && $name)) { + return false; + } + $r = q("SELECT id FROM pgrp WHERE uid = %d AND gname = '%s' LIMIT 1", + intval($uid), + dbesc($name) + ); + if ($r) { + return $r[0]['id']; + } + return false; + } + + static function by_id($uid,$id) { + if (! ($uid && $id)) { + return false; + } + + $r = q("SELECT * FROM pgrp WHERE uid = %d AND id = %d and deleted = 0", + intval($uid), + intval($id) + ); + if ($r) { + return array_shift($r); + } + return false; + } + + + + static function rec_byhash($uid,$hash) { + if (! ( $uid && $hash)) { + return false; + } + $r = q("SELECT * FROM pgrp WHERE uid = %d AND hash = '%s' LIMIT 1", + intval($uid), + dbesc($hash) + ); + if ($r) { + return array_shift($r); + } + return false; + } + + + static function member_remove($uid,$name,$member) { + $gid = self::byname($uid,$name); + if (! $gid) { + return false; + } + if (! ($uid && $gid && $member)) { + return false; + } + $r = q("DELETE FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' ", + intval($uid), + intval($gid), + dbesc($member) + ); + + Libsync::build_sync_packet($uid,null,true); + + return $r; + } + + + static function member_add($uid,$name,$member,$gid = 0) { + if (! $gid) { + $gid = self::byname($uid,$name); + } + if (! ($gid && $uid && $member)) { + return false; + } + + $r = q("SELECT * FROM pgrp_member WHERE uid = %d AND gid = %d AND xchan = '%s' LIMIT 1", + intval($uid), + intval($gid), + dbesc($member) + ); + if ($r) { + return true; // You might question this, but + // we indicate success because the group member was in fact created + // -- It was just created at another time + } + else { + $r = q("INSERT INTO pgrp_member (uid, gid, xchan) + VALUES( %d, %d, '%s' ) ", + intval($uid), + intval($gid), + dbesc($member) + ); + } + Libsync::build_sync_packet($uid,null,true); + return $r; + } + + + static function members($uid, $gid) { + $ret = []; + if (intval($gid)) { + $r = q("SELECT * FROM pgrp_member + LEFT JOIN abook ON abook_xchan = pgrp_member.xchan left join xchan on xchan_hash = abook_xchan + WHERE gid = %d AND abook_channel = %d and pgrp_member.uid = %d and xchan_deleted = 0 and abook_self = 0 and abook_blocked = 0 and abook_pending = 0 ORDER BY xchan_name ASC ", + intval($gid), + intval($uid), + intval($uid) + ); + if ($r) { + $ret = $r; + } + } + return $ret; + } + + static function members_xchan($uid,$gid) { + $ret = []; + if (intval($gid)) { + $r = q("SELECT xchan FROM pgrp_member WHERE gid = %d AND uid = %d", + intval($gid), + intval($uid) + ); + if ($r) { + foreach ($r as $rv) { + $ret[] = $rv['xchan']; + } + } + } + return $ret; + } + + static function members_profile_xchan($uid,$gid) { + $ret = []; + if (intval($gid)) { + $r = q("SELECT abook_xchan as xchan from abook left join profile on abook_profile = profile_guid where profile.id = %d and profile.uid = %d", + intval($gid), + intval($uid) + ); + if ($r) { + foreach($r as $rv) { + $ret[] = $rv['xchan']; + } + } + } + return $ret; + } + + + + + static function select($uid,$group = '') { + + $grps = []; + + $r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", + intval($uid) + ); + $grps[] = [ 'name' => '', 'hash' => '0', 'selected' => '' ]; + if ($r) { + foreach ($r as $rr) { + $grps[] = [ 'name' => $rr['gname'], 'id' => $rr['hash'], 'selected' => (($group == $rr['hash']) ? 'true' : '') ]; + } + + } + + return replace_macros(get_markup_template('group_selection.tpl'), [ + '$label' => t('Add new connections to this access list'), + '$groups' => $grps + ]); + } + + + static function widget($every="connections",$each="lists",$edit = false, $group_id = 0, $cid = '',$mode = 1) { + + $o = ''; + + $groups = []; + + $r = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC", + intval($_SESSION['uid']) + ); + $member_of = []; + if ($cid) { + $member_of = self::containing(local_channel(),$cid); + } + + if ($r) { + foreach ($r as $rr) { + $selected = (($group_id == $rr['id']) ? ' group-selected' : ''); + + if ($edit) { + $groupedit = [ 'href' => "lists/".$rr['id'], 'title' => t('edit') ]; + } + else { + $groupedit = null; + } + + $groups[] = [ + 'id' => $rr['id'], + 'enc_cid' => base64url_encode($cid), + 'cid' => $cid, + 'text' => $rr['gname'], + 'selected' => $selected, + 'href' => (($mode == 0) ? $each.'?f=&gid='.$rr['id'] : $each."/".$rr['id']) . ((x($_GET,'new')) ? '&new=' . $_GET['new'] : '') . ((x($_GET,'order')) ? '&order=' . $_GET['order'] : ''), + 'edit' => $groupedit, + 'ismember' => in_array($rr['id'],$member_of), + ]; + } + } + + return replace_macros(get_markup_template('group_side.tpl'), [ + '$title' => t('Lists'), + '$edittext' => t('Edit list'), + '$createtext' => t('Create new list'), + '$ungrouped' => (($every === 'contacts') ? t('Channels not in any access list') : ''), + '$groups' => $groups, + '$add' => t('add'), + ]); + + } + + + static function expand($g) { + if (! (is_array($g) && count($g))) { + return []; + } + + $ret = []; + $x = []; + + // private profile linked virtual groups + + foreach ($g as $gv) { + if (substr($gv,0,3) === 'vp.') { + $profile_hash = substr($gv,3); + if ($profile_hash) { + $r = q("select abook_xchan from abook where abook_profile = '%s'", + dbesc($profile_hash) + ); + if ($r) { + foreach ($r as $rv) { + $ret[] = $rv['abook_xchan']; + } + } + } + } + else { + $x[] = $gv; + } + } + + if ($x) { + stringify_array_elms($x,true); + $groups = implode(',', $x); + if ($groups) { + $r = q("SELECT xchan FROM pgrp_member WHERE gid IN ( select id from pgrp where hash in ( $groups ))"); + if ($r) { + foreach ($r as $rv) { + $ret[] = $rv['xchan']; + } + } + } + } + return $ret; + } + + + static function member_of($c) { + $r = q("SELECT pgrp.gname, pgrp.id FROM pgrp LEFT JOIN pgrp_member ON pgrp_member.gid = pgrp.id + WHERE pgrp_member.xchan = '%s' AND pgrp.deleted = 0 ORDER BY pgrp.gname ASC ", + dbesc($c) + ); + + return $r; + } + + static function containing($uid,$c) { + + $r = q("SELECT gid FROM pgrp_member WHERE uid = %d AND pgrp_member.xchan = '%s' ", + intval($uid), + dbesc($c) + ); + + $ret = []; + if ($r) { + foreach ($r as $rv) + $ret[] = $rv['gid']; + } + + return $ret; + } +} \ No newline at end of file diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php new file mode 100644 index 000000000..978a4ce39 --- /dev/null +++ b/Zotlabs/Lib/Connect.php @@ -0,0 +1,315 @@ + false, 'message' => '' ]; + + $my_perms = false; + $protocol = ''; + + if (substr($url,0,1) === '[') { + $x = strpos($url,']'); + if ($x) { + $protocol = substr($url,1,$x-1); + $url = substr($url,$x+1); + } + } + + if (! check_siteallowed($url)) { + $result['message'] = t('Channel is blocked on this site.'); + return $result; + } + + if (! $url) { + $result['message'] = t('Channel location missing.'); + return $result; + } + + // check service class limits + + $r = q("select count(*) as total from abook where abook_channel = %d and abook_self = 0 ", + intval($uid) + ); + if ($r) { + $total_channels = $r[0]['total']; + } + + if (! service_class_allows($uid,'total_channels',$total_channels)) { + $result['message'] = upgrade_message(); + return $result; + } + + $xchan_hash = ''; + $sql_options = (($protocol) ? " and xchan_network = '" . dbesc($protocol) . "' " : ''); + + $r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s') $sql_options ", + dbesc($url), + dbesc($url), + dbesc($url) + ); + + if ($r) { + + // reset results to the best record or the first if we don't have the best + // note: this is a single record and not an array of results + + $r = Libzot::zot_record_preferred($r,'xchan_network'); + + } + + $singleton = false; + $d = false; + + if (! $r) { + + // not in cache - try discovery + + $wf = discover_by_webbie($url,$protocol); + + if (! $wf) { + $feeds = get_config('system','feed_contacts'); + + if (($feeds) && (in_array($protocol, [ '', 'feed', 'rss' ]))) { + $d = discover_feed($url); + } + else { + $result['message'] = t('Remote channel or protocol unavailable.'); + return $result; + } + } + } + + if ($wf || $d) { + + // something was discovered - find the record which was just created. + + $r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' ) $sql_options", + dbesc(($wf) ? $wf : $url), + dbesc($url), + dbesc($url) + ); + + // convert to a single record (once again preferring a zot solution in the case of multiples) + + if ($r) { + $r = Libzot::zot_record_preferred($r,'xchan_network'); + } + } + + // if discovery was a success or the channel was already cached we should have an xchan record in $r + + if ($r) { + $xchan = $r; + $xchan_hash = $r['xchan_hash']; + $their_perms = EMPTY_STR; + } + + // failure case + + if (! $xchan_hash) { + $result['message'] = t('Channel discovery failed.'); + logger('follow: ' . $result['message']); + return $result; + } + + if (! check_channelallowed($xchan_hash)) { + $result['message'] = t('Channel is blocked on this site.'); + logger('follow: ' . $result['message']); + return $result; + + } + + $allowed = ((in_array($xchan['xchan_network'],['rss','zot','zot6'])) ? 1 : 0); + + $hookdata = ['channel_id' => $uid, 'follow_address' => $url, 'xchan' => $xchan, 'allowed' => $allowed, 'singleton' => 0]; + call_hooks('follow_allow',$hookdata); + + if(! $hookdata['allowed']) { + hz_syslog('zesz'); + $result['message'] = t('Protocol disabled.'); + return $result; + } + + $singleton = intval($hookdata['singleton']); + + // Now start processing the new connection + + $aid = $channel['channel_account_id']; + $default_group = $channel['channel_default_group']; + + if (in_array($xchan_hash, [$channel['channel_hash'], $channel['channel_portable_id']])) { + $result['message'] = t('Cannot connect to yourself.'); + return $result; + } + + if ($xchan['xchan_network'] === 'rss') { + + // check service class feed limits + + $t = q("select count(*) as total from abook where abook_account = %d and abook_feed = 1 ", + intval($aid) + ); + if ($t) { + $total_feeds = $t[0]['total']; + } + + if (! service_class_allows($uid,'total_feeds',$total_feeds)) { + $result['message'] = upgrade_message(); + return $result; + } + + // Always set these "remote" permissions for feeds since we cannot interact with them + // to negotiate a suitable permission response + + $p = get_abconfig($uid,$xchan_hash,'system','their_perms',EMPTY_STR); + if ($p) { + $p .= ','; + } + $p .= 'view_stream,republish'; + set_abconfig($uid,$xchan_hash,'system','their_perms',$p); + + } + + + $p = Permissions::connect_perms($uid); + + // parent channels have unencumbered write permission + + if ($sub_channel) { + $p['perms']['post_wall'] = 1; + $p['perms']['post_comments'] = 1; + $p['perms']['write_storage'] = 1; + $p['perms']['post_like'] = 1; + $p['perms']['delegate'] = 0; + $p['perms']['moderated'] = 0; + } + + $my_perms = Permissions::serialise($p['perms']); + + $profile_assign = get_pconfig($uid,'system','profile_assign',''); + + + // See if we are already connected by virtue of having an abook record + + $r = q("select abook_id, abook_xchan, abook_pending, abook_instance from abook + where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($xchan_hash), + intval($uid) + ); + + if ($r) { + + $abook_instance = $r[0]['abook_instance']; + + // If they are on a non-nomadic network, add them to this location + + if (($singleton) && strpos($abook_instance,z_root()) === false) { + if ($abook_instance) { + $abook_instance .= ','; + } + $abook_instance .= z_root(); + + $x = q("update abook set abook_instance = '%s', abook_not_here = 0 where abook_id = %d", + dbesc($abook_instance), + intval($r[0]['abook_id']) + ); + } + + // if they have a pending connection, we just followed them so approve the connection request + + if (intval($r[0]['abook_pending'])) { + $x = q("update abook set abook_pending = 0 where abook_id = %d", + intval($r[0]['abook_id']) + ); + } + } + else { + + // create a new abook record + + $closeness = get_pconfig($uid,'system','new_abook_closeness',80); + + $r = abook_store_lowlevel( + [ + 'abook_account' => intval($aid), + 'abook_channel' => intval($uid), + 'abook_closeness' => intval($closeness), + 'abook_xchan' => $xchan_hash, + 'abook_profile' => $profile_assign, + 'abook_feed' => intval(($xchan['xchan_network'] === 'rss') ? 1 : 0), + 'abook_created' => datetime_convert(), + 'abook_updated' => datetime_convert(), + 'abook_instance' => (($singleton) ? z_root() : '') + ] + ); + } + + if (! $r) { + logger('abook creation failed'); + $result['message'] = t('error saving data'); + return $result; + } + + // Set suitable permissions to the connection + + if ($my_perms) { + set_abconfig($uid,$xchan_hash,'system','my_perms',$my_perms); + } + + // fetch the entire record + + $r = q("select abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash + where abook_xchan = '%s' and abook_channel = %d limit 1", + dbesc($xchan_hash), + intval($uid) + ); + + if ($r) { + $result['abook'] = array_shift($r); + Master::Summon([ 'Notifier', 'permission_create', $result['abook']['abook_id'] ]); + } + + $arr = [ 'channel_id' => $uid, 'channel' => $channel, 'abook' => $result['abook'] ]; + + call_hooks('follow', $arr); + + /** If there is a default group for this channel, add this connection to it */ + + if ($default_group) { + $g = AccessList::rec_byhash($uid,$default_group); + if ($g) { + AccessList::member_add($uid,'',$xchan_hash,$g['id']); + } + } + + $result['success'] = true; + return $result; + } +} -- cgit v1.2.3 From 3df5d854b8935b11c67893bbbd24cdf8829eda00 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Wed, 29 Jan 2020 14:29:06 -0800 Subject: z6 transition work - prevent z6 sync packets from being unpacked into an incompatible schema --- Zotlabs/Lib/Libsync.php | 4 ++-- Zotlabs/Lib/Libzot.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index d93270bc5..b9e9bb38a 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -83,7 +83,7 @@ class Libsync { $info = (($packet) ? $packet : array()); $info['type'] = 'sync'; - $info['encoding'] = 'red'; // note: not zot, this packet is very platform specific + $info['encoding'] = 'hz'; // note: not zot, this packet is very platform specific $info['relocate'] = ['channel_address' => $channel['channel_address'], 'url' => z_root() ]; if(array_key_exists($uid,\App::$config) && array_key_exists('transient',\App::$config[$uid])) { @@ -144,7 +144,7 @@ class Libsync { foreach($synchubs as $hub) { $hash = random_string(); - $n = Libzot::build_packet($channel,'sync',$env_recips,json_encode($info),'red',$hub['hubloc_sitekey'],$hub['site_crypto']); + $n = Libzot::build_packet($channel,'sync',$env_recips,json_encode($info),'hz',$hub['hubloc_sitekey'],$hub['site_crypto']); Queue::insert(array( 'hash' => $hash, 'account_id' => $channel['channel_account_id'], diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index ad00aa97a..bb70dfbf2 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1277,7 +1277,12 @@ class Libzot { logger('Channel sync received: ' . print_r($arr,true), LOGGER_DATA, LOG_DEBUG); logger('Channel sync recipients: ' . print_r($deliveries,true), LOGGER_DATA, LOG_DEBUG); - $result = Libsync::process_channel_sync_delivery($env['sender'],$arr,$deliveries); + if ($env['encoding'] === 'hz') { + $result = Libsync::process_channel_sync_delivery($env['sender'],$arr,$deliveries); + } + else { + logger('sync packet type not supported.'); + } } } if ($result) { -- cgit v1.2.3 From 19bb9e018152ce528846fb955b58d76f1bb6bdec Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Jan 2020 10:12:45 +0000 Subject: zap is storing perms different from hubzilla - revert Lib/Connect to use the hubzilla way. Eventually we might want to streamline this with zap. This will require a DB update to upgrade permissions in abconfig. --- Zotlabs/Lib/Connect.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php index 978a4ce39..5fc0e3fe1 100644 --- a/Zotlabs/Lib/Connect.php +++ b/Zotlabs/Lib/Connect.php @@ -152,7 +152,6 @@ class Connect { call_hooks('follow_allow',$hookdata); if(! $hookdata['allowed']) { - hz_syslog('zesz'); $result['message'] = t('Protocol disabled.'); return $result; } @@ -211,7 +210,7 @@ class Connect { $p['perms']['moderated'] = 0; } - $my_perms = Permissions::serialise($p['perms']); + $my_perms = $p['perms']; $profile_assign = get_pconfig($uid,'system','profile_assign',''); @@ -279,8 +278,10 @@ class Connect { // Set suitable permissions to the connection - if ($my_perms) { - set_abconfig($uid,$xchan_hash,'system','my_perms',$my_perms); + if($my_perms) { + foreach($my_perms as $k => $v) { + set_abconfig($uid,$xchan_hash,'my_perms',$k,$v); + } } // fetch the entire record -- cgit v1.2.3 From 2c42daf6090ba8d0e3a50b8350ea5a3750891b68 Mon Sep 17 00:00:00 2001 From: Zot Date: Thu, 30 Jan 2020 20:06:15 +0100 Subject: z6 compat work --- Zotlabs/Lib/Libsync.php | 4 ++-- Zotlabs/Lib/Libzot.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index d93270bc5..b9e9bb38a 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -83,7 +83,7 @@ class Libsync { $info = (($packet) ? $packet : array()); $info['type'] = 'sync'; - $info['encoding'] = 'red'; // note: not zot, this packet is very platform specific + $info['encoding'] = 'hz'; // note: not zot, this packet is very platform specific $info['relocate'] = ['channel_address' => $channel['channel_address'], 'url' => z_root() ]; if(array_key_exists($uid,\App::$config) && array_key_exists('transient',\App::$config[$uid])) { @@ -144,7 +144,7 @@ class Libsync { foreach($synchubs as $hub) { $hash = random_string(); - $n = Libzot::build_packet($channel,'sync',$env_recips,json_encode($info),'red',$hub['hubloc_sitekey'],$hub['site_crypto']); + $n = Libzot::build_packet($channel,'sync',$env_recips,json_encode($info),'hz',$hub['hubloc_sitekey'],$hub['site_crypto']); Queue::insert(array( 'hash' => $hash, 'account_id' => $channel['channel_account_id'], diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index ad00aa97a..bb70dfbf2 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1277,7 +1277,12 @@ class Libzot { logger('Channel sync received: ' . print_r($arr,true), LOGGER_DATA, LOG_DEBUG); logger('Channel sync recipients: ' . print_r($deliveries,true), LOGGER_DATA, LOG_DEBUG); - $result = Libsync::process_channel_sync_delivery($env['sender'],$arr,$deliveries); + if ($env['encoding'] === 'hz') { + $result = Libsync::process_channel_sync_delivery($env['sender'],$arr,$deliveries); + } + else { + logger('sync packet type not supported.'); + } } } if ($result) { -- cgit v1.2.3 From 8ed3971ef05be4015b65c9a5b721954c7767ba22 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 30 Jan 2020 20:18:25 +0100 Subject: Prevent multiple database requests on name platform check --- Zotlabs/Lib/System.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/System.php b/Zotlabs/Lib/System.php index 7bf1343bb..3f500486c 100644 --- a/Zotlabs/Lib/System.php +++ b/Zotlabs/Lib/System.php @@ -5,9 +5,14 @@ namespace Zotlabs\Lib; class System { static public function get_platform_name() { - if(is_array(\App::$config) && is_array(\App::$config['system']) && array_key_exists('platform_name',\App::$config['system'])) - return \App::$config['system']['platform_name']; - return PLATFORM_NAME; + + if(! isset($platform_name)) { + if(is_array(\App::$config) && is_array(\App::$config['system']) && array_key_exists('platform_name',\App::$config['system'])) + static $platform_name = \App::$config['system']['platform_name']; + else + static $platform_name = PLATFORM_NAME; + } + return $platform_name; } static public function get_site_name() { -- cgit v1.2.3 From 5e76318e44d682ce631aa575550ce666eff2ea79 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 30 Jan 2020 20:28:55 +0100 Subject: Update System.php --- Zotlabs/Lib/System.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/System.php b/Zotlabs/Lib/System.php index 3f500486c..b66f66bce 100644 --- a/Zotlabs/Lib/System.php +++ b/Zotlabs/Lib/System.php @@ -6,11 +6,12 @@ class System { static public function get_platform_name() { - if(! isset($platform_name)) { + static $platform_name = ''; + if(empty($platform_name)) { if(is_array(\App::$config) && is_array(\App::$config['system']) && array_key_exists('platform_name',\App::$config['system'])) - static $platform_name = \App::$config['system']['platform_name']; + $platform_name = \App::$config['system']['platform_name']; else - static $platform_name = PLATFORM_NAME; + $platform_name = PLATFORM_NAME; } return $platform_name; } -- cgit v1.2.3 From b37e5a426abee519f20a9cec557538bde3841ad8 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 30 Jan 2020 20:36:00 +0100 Subject: Update System.php --- Zotlabs/Lib/System.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/System.php b/Zotlabs/Lib/System.php index b66f66bce..3cc46fbda 100644 --- a/Zotlabs/Lib/System.php +++ b/Zotlabs/Lib/System.php @@ -5,8 +5,7 @@ namespace Zotlabs\Lib; class System { static public function get_platform_name() { - - static $platform_name = ''; + static $platform_name = ''; if(empty($platform_name)) { if(is_array(\App::$config) && is_array(\App::$config['system']) && array_key_exists('platform_name',\App::$config['system'])) $platform_name = \App::$config['system']['platform_name']; -- cgit v1.2.3 From 989443a5698adf5e7a93f874048699526aa103a7 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 30 Jan 2020 15:56:33 -0800 Subject: 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 --- Zotlabs/Lib/Activity.php | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 43315a87f..66b1ee4b8 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -813,6 +813,10 @@ class Activity { static function activity_mapper($verb) { + if ($verb === 'Answer') { + return 'Note'; + } + if(strpos($verb,'/') === false) { return $verb; } @@ -932,10 +936,6 @@ class Activity { static function activity_obj_mapper($obj) { - if(strpos($obj,'/') === false) { - return $obj; - } - $objs = [ 'http://activitystrea.ms/schema/1.0/note' => 'Note', 'http://activitystrea.ms/schema/1.0/comment' => 'Note', @@ -956,6 +956,15 @@ class Activity { call_hooks('activity_obj_mapper',$objs); + if ($obj === 'Answer') { + return 'Note'; + } + + if (strpos($obj,'/') === false) { + return $obj; + } + + if(array_key_exists($obj,$objs)) { return $objs[$obj]; } @@ -1644,6 +1653,13 @@ class Activity { $s['expires'] = datetime_convert('UTC','UTC',$act->obj['expires']); } + if ($act->type === 'Note' && $act->obj['type'] === 'Question' && $act->data['name']) { + $s['mid'] = $act->id; + $s['parent_mid'] = $act->obj['id']; + $s['replyto'] = $act->replyto; + $s['verb'] = 'Answer'; + $content['content'] = EMPTY_STR; + } if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction' ])) { @@ -1711,6 +1727,15 @@ class Activity { $s['verb'] = self::activity_decode_mapper($act->type); + if ($act->type === 'Note' && $act->obj['type'] === 'Question' && $act->data['name'] && ! $content['content']) { + $s['verb'] = 'Answer'; + $s['title'] = purify_html($act->data['name']); + } + + // Mastodon does not provide update timestamps when updating poll tallies which means race conditions may occur here. + if ($act->type === 'Update' && $act->obj['type'] === 'Question' && $s['edited'] === $s['created']) { + $s['edited'] = datetime_convert(); + } if($act->type === 'Tombstone' || $act->type === 'Delete' || ($act->type === 'Create' && $act->obj['type'] === 'Tombstone')) { $s['item_deleted'] = 1; @@ -1798,6 +1823,18 @@ class Activity { } + 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']); + } + } + + if ($act->obj['closed']) { + $s['comments_closed'] = datetime_convert('UTC','UTC', $act->obj['closed']); + } + + + // we will need a hook here to extract magnet links e.g. peertube // right now just link to the largest mp4 we find that will fit in our // standard content region -- cgit v1.2.3 From fc9e6d289acf30f89da0051a90cbf16f0bc006fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Fri, 31 Jan 2020 12:51:23 -0800 Subject: missing piece of poll code --- Zotlabs/Lib/Activity.php | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 66b1ee4b8..edc65d8e9 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1615,6 +1615,73 @@ class Activity { } + + static function update_poll($item,$mid,$content) { + $multi = false; + if (! $item) { + return false; + } + + $o = json_decode($item['obj'],true); + if ($o && array_key_exists('anyOf',$o)) { + $multi = true; + } + $answer_found = false; + $found = false; + if ($multi) { + for ($c = 0; $c < count($o['anyOf']); $c ++) { + if ($o['anyOf'][$c]['name'] === $content) { + $answer_found = true; + if (is_array($o['anyOf'][$c]['replies'])) { + foreach($o['anyOf'][$c]['replies'] as $reply) { + if(array_key_exists('id',$reply) && $reply['id'] === $mid) { + $found = true; + } + } + } + + if (! $found) { + $o['anyOf'][$c]['replies']['totalItems'] ++; + $o['anyOf'][$c]['replies']['items'][] = [ 'id' => $mid, 'type' => 'Note' ]; + } + } + } + } + else { + for ($c = 0; $c < count($o['oneOf']); $c ++) { + if ($o['oneOf'][$c]['name'] === $content) { + $answer_found = true; + if (is_array($o['oneOf'][$c]['replies'])) { + foreach($o['oneOf'][$c]['replies'] as $reply) { + if(array_key_exists('id',$reply) && $reply['id'] === $mid) { + $found = true; + } + } + } + + if (! $found) { + $o['oneOf'][$c]['replies']['totalItems'] ++; + $o['oneOf'][$c]['replies']['items'][] = [ 'id' => $mid, 'type' => 'Note' ]; + } + } + } + } + logger('updated_poll: ' . print_r($o,true),LOGGER_DATA); + if ($answer_found && ! $found) { + $x = q("update item set obj = '%s', edited = '%s' where id = %d", + dbesc(json_encode($o)), + dbesc(datetime_convert()), + intval($item['id']) + ); + Master::Summon( [ 'Notifier', 'wall-new', $item['id'] ] ); + return true; + } + + return false; + } + + + static function decode_note($act) { $response_activity = false; -- cgit v1.2.3 From bbcb237f5b996e94af37611152105b2e965ea493 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 9 Feb 2020 16:32:18 -0800 Subject: poll updates --- Zotlabs/Lib/Activity.php | 44 +++++++++++++++++++++++++------------------- Zotlabs/Lib/Libzot.php | 12 +++++++++++- 2 files changed, 36 insertions(+), 20 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index edc65d8e9..06aa3b931 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -325,6 +325,22 @@ class Activity { $ret['type'] = $objtype; + if ($objtype === 'Question') { + if ($i['obj']) { + if (is_array($i['obj'])) { + $ret = $i['obj']; + } + else { + $ret = json_decode($i['obj'],true); + } + + if(array_path_exists('actor/id',$ret)) { + $ret['actor'] = $ret['actor']['id']; + } + } + } + + $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid'])); if($i['title']) @@ -813,10 +829,6 @@ class Activity { static function activity_mapper($verb) { - if ($verb === 'Answer') { - return 'Note'; - } - if(strpos($verb,'/') === false) { return $verb; } @@ -916,7 +928,6 @@ class Activity { 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', 'Invite' => 'Invite', - ]; call_hooks('activity_obj_decode_mapper',$objs); @@ -1720,14 +1731,6 @@ class Activity { $s['expires'] = datetime_convert('UTC','UTC',$act->obj['expires']); } - if ($act->type === 'Note' && $act->obj['type'] === 'Question' && $act->data['name']) { - $s['mid'] = $act->id; - $s['parent_mid'] = $act->obj['id']; - $s['replyto'] = $act->replyto; - $s['verb'] = 'Answer'; - $content['content'] = EMPTY_STR; - } - if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction' ])) { $response_activity = true; @@ -1794,11 +1797,6 @@ class Activity { $s['verb'] = self::activity_decode_mapper($act->type); - if ($act->type === 'Note' && $act->obj['type'] === 'Question' && $act->data['name'] && ! $content['content']) { - $s['verb'] = 'Answer'; - $s['title'] = purify_html($act->data['name']); - } - // Mastodon does not provide update timestamps when updating poll tallies which means race conditions may occur here. if ($act->type === 'Update' && $act->obj['type'] === 'Question' && $s['edited'] === $s['created']) { $s['edited'] = datetime_convert(); @@ -2190,7 +2188,7 @@ class Activity { set_iconfig($item,'activitypub','recips',$act->raw_recips); if(! $is_parent) { - $p = q("select parent_mid from item where mid = '%s' and uid = %d limit 1", + $p = q("select parent_mid, id, obj_type from item where mid = '%s' and uid = %d limit 1", dbesc($item['parent_mid']), intval($item['uid']) ); @@ -2220,6 +2218,14 @@ class Activity { // $s['thr_parent'] = $s['mid']; } } + + if ($p[0]['obj_type'] === 'Question') { + if ($item['obj_type'] === ACTIVITY_OBJ_NOTE && $item['title'] && (! $item['content'])) { + $item['obj_type'] = 'Answer'; + } + } + + if($p[0]['parent_mid'] !== $item['parent_mid']) { $item['thr_parent'] = $item['parent_mid']; } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index bb70dfbf2..2776a681e 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1613,7 +1613,7 @@ class Libzot { // As a side effect we will also do a preliminary check that we have the top-level-post, otherwise // processing it is pointless. - $r = q("select route, id, owner_xchan, item_private from item where mid = '%s' and uid = %d limit 1", + $r = q("select route, id, parent_mid, mid, owner_xchan, item_private, obj_type from item where mid = '%s' and uid = %d limit 1", dbesc($arr['parent_mid']), intval($channel['channel_id']) ); @@ -1639,6 +1639,16 @@ class Libzot { continue; } + if ($r[0]['obj_type'] === 'Question') { + // route checking doesn't work correctly here because we've changed the privacy + $r[0]['route'] = EMPTY_STR; + // If this is a poll response, convert the obj_type to our (internal-only) "Answer" type + if ($arr['obj_type'] === ACTIVITY_OBJ_NOTE && $arr['title'] && (! $arr['content'])) { + $arr['obj_type'] = 'Answer'; + } + } + + if($relay || $friendofriend || (intval($r[0]['item_private']) === 0 && intval($arr['item_private']) === 0)) { // reset the route in case it travelled a great distance upstream // use our parent's route so when we go back downstream we'll match -- cgit v1.2.3 From a39d436f9f46138db623ee3c9ddef2c501ea8bd2 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 10 Feb 2020 20:37:35 +0000 Subject: poll fixes --- Zotlabs/Lib/Activity.php | 7 ++++++- Zotlabs/Lib/Libzot.php | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 06aa3b931..5a406beb7 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -928,6 +928,7 @@ class Activity { 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', 'Invite' => 'Invite', + 'Question' => 'Question' ]; call_hooks('activity_obj_decode_mapper',$objs); @@ -962,7 +963,8 @@ class Activity { 'http://purl.org/zot/activity/thing' => 'Object', 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', - 'Invite' => 'Invite', + 'Invite' => 'Invite', + 'Question' => 'Question' ]; call_hooks('activity_obj_mapper',$objs); @@ -1806,6 +1808,8 @@ class Activity { $s['item_deleted'] = 1; } + + $s['obj_type'] = self::activity_obj_decode_mapper($act->obj['type']); if($s['obj_type'] === ACTIVITY_OBJ_NOTE && $s['mid'] !== $s['parent_mid']) { $s['obj_type'] = ACTIVITY_OBJ_COMMENT; @@ -2219,6 +2223,7 @@ class Activity { } } + if ($p[0]['obj_type'] === 'Question') { if ($item['obj_type'] === ACTIVITY_OBJ_NOTE && $item['title'] && (! $item['content'])) { $item['obj_type'] = 'Answer'; diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 2776a681e..d64421926 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1643,7 +1643,7 @@ class Libzot { // route checking doesn't work correctly here because we've changed the privacy $r[0]['route'] = EMPTY_STR; // If this is a poll response, convert the obj_type to our (internal-only) "Answer" type - if ($arr['obj_type'] === ACTIVITY_OBJ_NOTE && $arr['title'] && (! $arr['content'])) { + if ($arr['obj_type'] === ACTIVITY_OBJ_COMMENT && $arr['title'] && (! $arr['body'])) { $arr['obj_type'] = 'Answer'; } } -- cgit v1.2.3 From d4a6aa7801d7bad862436990418a7aba34ddef1f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 10 Feb 2020 15:34:33 -0800 Subject: this allows polls to federate from hubzilla to zap, though still a remaining issue with voting --- Zotlabs/Lib/Activity.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 5a406beb7..1ac3135db 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -592,8 +592,15 @@ class Activity { } } - - $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/activity/' . urlencode($i['mid'])); + if (strpos($i['mid'],z_root() . '/item/') !== false) { + $ret['id'] = str_replace('/item/','/activity/',$i['mid']); + } + elseif (strpos($i['mid'],z_root() . '/event/') !== false) { + $ret['id'] = str_replace('/event/','/activity/',$i['mid']); + } + else { + $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/activity/' . urlencode($i['mid'])); + } if($i['title']) $ret['name'] = html2plain(bbcode($i['title'], [ 'cache' => true ])); -- cgit v1.2.3 From bf7c96807a50433b7241ddf6df9e01d4ef11f43d Mon Sep 17 00:00:00 2001 From: zotlabs Date: Mon, 10 Feb 2020 18:17:41 -0800 Subject: fix poll responses --- Zotlabs/Lib/Libzot.php | 1 + 1 file changed, 1 insertion(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index d64421926..42e706754 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1617,6 +1617,7 @@ class Libzot { dbesc($arr['parent_mid']), intval($channel['channel_id']) ); + if(! $r) { $DR->update('comment parent not found'); $result[] = $DR->get(); -- cgit v1.2.3 From 9f029336cab322e04d29af842ba0a666189c8683 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 11 Feb 2020 09:20:32 +0000 Subject: fix notifications for polls --- Zotlabs/Lib/Enotify.php | 5 +++-- Zotlabs/Lib/ThreadItem.php | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index f6f8ad0cb..85e90d67c 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -810,8 +810,9 @@ class Enotify { } else { $itemem_text = (($item['item_thread_top']) - ? t('created a new post') - : sprintf( t('commented on %s\'s post'), '[bdi]' . $item['owner']['xchan_name'] . '[/bdi]')); + ? (($item['obj_type'] === 'Question') ? t('created a new poll') : t('created a new post')) + : (($item['obj_type'] === 'Answer') ? sprintf( t('voted on %s\'s poll'), '[bdi]' . $item['owner']['xchan_name'] . '[/bdi]') : sprintf( t('commented on %s\'s post'), '[bdi]' . $item['owner']['xchan_name'] . '[/bdi]')) + ); if($item['verb'] === ACTIVITY_SHARE) { $itemem_text = sprintf( t('repeated %s\'s post'), '[bdi]' . $item['author']['xchan_name'] . '[/bdi]'); diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 2386a1f0d..dee7cda56 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -204,6 +204,10 @@ class ThreadItem { } } + if($item['obj_type'] === 'Question') { + $response_verbs[] = 'answer'; + } + $consensus = (intval($item['item_consensus']) ? true : false); if($consensus) { $response_verbs[] = 'agree'; -- cgit v1.2.3 From b7bac45427a400275597faa9b51c4d277fe1f5c7 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 20 Feb 2020 20:03:50 +0100 Subject: Revert "Use argv() instead URI parsing" This reverts commit bcfb69eeeef6a0506a0ec0574a03b673df84a55a --- Zotlabs/Lib/Libsync.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index b9e9bb38a..d1756cf47 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -244,7 +244,10 @@ class Libsync { if(array_key_exists('app',$arr) && $arr['app']) sync_apps($channel,$arr['app']); - + + if(array_key_exists('addressbook',$arr) && $arr['addressbook']) + sync_addressbook($channel,$arr['addressbook']); + if(array_key_exists('chatroom',$arr) && $arr['chatroom']) sync_chatrooms($channel,$arr['chatroom']); -- cgit v1.2.3 From 60311eb04bc0fa564b9fbe179eb907989ff09d8f Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 20 Feb 2020 21:25:41 +0000 Subject: fix warning --- Zotlabs/Lib/Activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 1ac3135db..5cb111381 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1654,7 +1654,7 @@ class Activity { $answer_found = true; if (is_array($o['anyOf'][$c]['replies'])) { foreach($o['anyOf'][$c]['replies'] as $reply) { - if(array_key_exists('id',$reply) && $reply['id'] === $mid) { + if(is_array($reply) && array_key_exists('id',$reply) && $reply['id'] === $mid) { $found = true; } } @@ -1673,7 +1673,7 @@ class Activity { $answer_found = true; if (is_array($o['oneOf'][$c]['replies'])) { foreach($o['oneOf'][$c]['replies'] as $reply) { - if(array_key_exists('id',$reply) && $reply['id'] === $mid) { + if(is_array($reply) && array_key_exists('id',$reply) && $reply['id'] === $mid) { $found = true; } } -- cgit v1.2.3 From 85cf25a2a8bfbbfe10de485d4affd54626fbbfa4 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 23 Feb 2020 15:28:16 -0800 Subject: add iconfig to zot6 objects --- Zotlabs/Lib/Activity.php | 52 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 1ac3135db..0d8dab95c 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) { @@ -1888,17 +1925,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']); -- cgit v1.2.3 From 989fbe70cd566da4c5757527aa77022036af6274 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Mon, 24 Feb 2020 10:02:09 +0100 Subject: Implement DAV calendars sync with clones --- Zotlabs/Lib/Libsync.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index d1756cf47..c39720735 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -246,7 +246,10 @@ class Libsync { sync_apps($channel,$arr['app']); if(array_key_exists('addressbook',$arr) && $arr['addressbook']) - sync_addressbook($channel,$arr['addressbook']); + sync_addressbook($channel,$arr['addressbook']); + + if(array_key_exists('calendar',$arr) && $arr['calendar']) + sync_calendar($channel,$arr['calendar']); if(array_key_exists('chatroom',$arr) && $arr['chatroom']) sync_chatrooms($channel,$arr['chatroom']); -- cgit v1.2.3 From c74c41c3b88669802c96c565f04b2682a54d43e9 Mon Sep 17 00:00:00 2001 From: BattleMage Date: Thu, 27 Feb 2020 11:44:51 +0100 Subject: Allow wiki link titles Allow linking to wiki pages with alternating titles by separating the title from the link with a pipe, like regular wiki markup does. --- Zotlabs/Lib/NativeWikiPage.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') 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) { -- cgit v1.2.3 From 06f2979e04db2c5eb7e10bc4967d750209a4cc73 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 29 Feb 2020 10:25:22 +0000 Subject: prevent duplicate votes --- Zotlabs/Lib/Activity.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 2f219af1f..02ec7614e 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1673,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; } @@ -1683,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) { -- cgit v1.2.3 From c358aa2806717d1af6e47697f87e54b7c9967c9e Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 12 Mar 2020 18:27:16 +0000 Subject: first batch of zot6 transition patches. basic communication with transitioned channels *should* work now --- Zotlabs/Lib/Libzot.php | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 42e706754..5e212ad70 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -105,7 +105,7 @@ class Libzot { $data = [ 'type' => $type, 'encoding' => $encoding, - 'sender' => $channel['channel_portable_id'], + 'sender' => $channel['channel_hash'], 'site_id' => self::make_xchan_hash(z_root(), get_config('system','pubkey')), 'version' => System::get_zot_revision(), ]; @@ -422,7 +422,7 @@ class Libzot { [ 'type' => NOTIFY_INTRO, 'from_xchan' => $x['hash'], - 'to_xchan' => $channel['channel_portable_id'], + 'to_xchan' => $channel['channel_hash'], 'link' => z_root() . '/connedit/' . $new_connection[0]['abook_id'] ] ); @@ -788,7 +788,7 @@ class Libzot { // see if this is a channel clone that's hosted locally - which we treat different from other xchans/connections - $local = q("select channel_account_id, channel_id from channel where channel_portable_id = '%s' limit 1", + $local = q("select channel_account_id, channel_id from channel where channel_hash = '%s' limit 1", dbesc($xchan_hash) ); if($local) { @@ -1151,7 +1151,7 @@ class Libzot { if($recip_arr) { stringify_array_elms($recip_arr,true); $recips = implode(',',$recip_arr); - $r = q("select channel_portable_id as hash from channel where channel_portable_id in ( " . $recips . " ) and channel_removed = 0 "); + $r = q("select channel_hash as hash from channel where channel_hash in ( " . $recips . " ) and channel_removed = 0 "); } if(! $r) { @@ -1368,12 +1368,12 @@ class Libzot { $r = []; - $c = q("select channel_id, channel_portable_id from channel where channel_removed = 0"); + $c = q("select channel_id, channel_hash from channel where channel_removed = 0"); if($c) { foreach($c as $cc) { if(perm_is_allowed($cc['channel_id'],$msg['sender'],$perm)) { - $r[] = $cc['channel_portable_id']; + $r[] = $cc['channel_hash']; } } } @@ -1381,7 +1381,7 @@ class Libzot { if($include_sys) { $sys = get_sys_channel(); if($sys) - $r[] = $sys['channel_portable_id']; + $r[] = $sys['channel_hash']; } @@ -1397,7 +1397,7 @@ class Libzot { if($tag['type'] === 'Mention' && (strpos($tag['href'],z_root()) !== false)) { $address = basename($tag['href']); if($address) { - $z = q("select channel_portable_id as hash from channel where channel_address = '%s' + $z = q("select channel_hash as hash from channel where channel_address = '%s' and channel_removed = 0 limit 1", dbesc($address) ); @@ -1418,7 +1418,7 @@ class Libzot { $thread_parent = self::find_parent($msg,$act); if($thread_parent) { - $z = q("select channel_portable_id as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) ", + $z = q("select channel_hash as hash from channel left join item on channel.channel_id = item.uid where ( item.thr_parent = '%s' OR item.parent_mid = '%s' ) ", dbesc($thread_parent), dbesc($thread_parent) ); @@ -1473,7 +1473,7 @@ class Libzot { $DR = new DReport(z_root(),$sender,$d,$arr['mid']); - $channel = channelx_by_portid($d); + $channel = channelx_by_hash($d); if (! $channel) { $DR->update('recipient not found'); @@ -1510,7 +1510,7 @@ class Libzot { * access checks. */ - if($sender === $channel['channel_portable_id'] && $arr['author_xchan'] === $channel['channel_portable_id'] && $arr['mid'] === $arr['parent_mid']) { + if($sender === $channel['channel_hash'] && $arr['author_xchan'] === $channel['channel_hash'] && $arr['mid'] === $arr['parent_mid']) { $DR->update('self delivery ignored'); $result[] = $DR->get(); continue; @@ -1827,7 +1827,7 @@ class Libzot { $stored = (($item_result && $item_result['item']) ? $item_result['item'] : false); if((is_array($stored)) && ($stored['id'] != $stored['parent']) - && ($stored['author_xchan'] === $channel['channel_hash'] || $stored['author_xchan'] === $channel['channel_portable_id'])) { + && ($stored['author_xchan'] === $channel['channel_hash'] || $stored['author_xchan'] === $channel['channel_hash'])) { retain_item($stored['item']['parent']); } @@ -1949,9 +1949,9 @@ class Libzot { } logger('FOF Activity received: ' . print_r($arr,true), LOGGER_DATA, LOG_DEBUG); - logger('FOF Activity recipient: ' . $channel['channel_portable_id'], LOGGER_DATA, LOG_DEBUG); + logger('FOF Activity recipient: ' . $channel['channel_hash'], LOGGER_DATA, LOG_DEBUG); - $result = self::process_delivery($arr['owner_xchan'],$AS, $arr, [ $channel['channel_portable_id'] ],false,false,true); + $result = self::process_delivery($arr['owner_xchan'],$AS, $arr, [ $channel['channel_hash'] ],false,false,true); if ($result) { $ret = array_merge($ret, $result); } @@ -2207,7 +2207,7 @@ class Libzot { $DR = new DReport(z_root(),$sender,$d,$arr['mid']); - $r = q("select * from channel where channel_portable_id = '%s' limit 1", + $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($d['hash']) ); @@ -2362,7 +2362,7 @@ class Libzot { $loc = $locations[0]; - $r = q("select * from channel where channel_portable_id = '%s' limit 1", + $r = q("select * from channel where channel_hash = '%s' limit 1", dbesc($sender_hash) ); @@ -2370,7 +2370,7 @@ class Libzot { return; if($loc['url'] !== z_root()) { - $x = q("update channel set channel_moved = '%s' where channel_portable_id = '%s' limit 1", + $x = q("update channel set channel_moved = '%s' where channel_hash = '%s' limit 1", dbesc($loc['url']), dbesc($sender_hash) ); @@ -2404,7 +2404,7 @@ class Libzot { static function encode_locations($channel) { $ret = []; - $x = self::get_hublocs($channel['channel_portable_id']); + $x = self::get_hublocs($channel['channel_hash']); if($x && count($x)) { foreach($x as $hub) { @@ -2752,13 +2752,13 @@ class Libzot { $r = null; if(strlen($zhash)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash - where channel_portable_id = '%s' limit 1", + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash + where channel_hash = '%s' limit 1", dbesc($zhash) ); } elseif(strlen($zguid) && strlen($zguid_sig)) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash where channel_guid = '%s' and channel_guid_sig = '%s' limit 1", dbesc($zguid), dbesc($zguid_sig) @@ -2766,7 +2766,7 @@ class Libzot { } elseif(strlen($zaddr)) { if(strpos($zaddr,'[system]') === false) { /* normal address lookup */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash where ( channel_address = '%s' or xchan_addr = '%s' ) limit 1", dbesc($zaddr), dbesc($zaddr) @@ -2786,10 +2786,10 @@ class Libzot { * */ - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash where channel_system = 1 order by channel_id limit 1"); if(! $r) { - $r = q("select channel.*, xchan.* from channel left join xchan on channel_portable_id = xchan_hash + $r = q("select channel.*, xchan.* from channel left join xchan on channel_hash = xchan_hash where channel_removed = 0 order by channel_id limit 1"); } } -- cgit v1.2.3 From a3acec96745f90443de84d8503334b3a204436fb Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 24 Mar 2020 18:26:20 -0700 Subject: issue 1454 - some photo item ActivityStreams links not returning json-ld; requires related fixes in addons/pubcrawl --- Zotlabs/Lib/Activity.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 02ec7614e..c50606d4f 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -323,6 +323,11 @@ class Activity { return $ret; } + + if ($i['obj']) { + $ret = Activity::encode_object($i['obj']); + } + $ret['type'] = $objtype; if ($objtype === 'Question') { -- cgit v1.2.3 From 0c1c386a0af1e8dabaf7acf345dffa5cf5ad89eb Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 25 Mar 2020 11:29:00 +0000 Subject: do not use channel_portable_id in process_channel_sync_delivery(). we should only accept sync packages from channels which are already transitioned to zot6. --- Zotlabs/Lib/Libsync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index c39720735..de389c0a9 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -1022,4 +1022,4 @@ class Libsync { } -} \ No newline at end of file +} -- cgit v1.2.3 From b739f91caa1522522a4ce093d7c63f0f4c777085 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 29 Mar 2020 15:18:49 +0000 Subject: use Libsync::build_sync_packet() in mod item, default Lib/Queue driver to zot6 and some whitespace cleanup in queue_deliver() --- Zotlabs/Lib/Libsync.php | 1 + Zotlabs/Lib/Queue.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index de389c0a9..b7cda1770 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -150,6 +150,7 @@ class Libsync { 'account_id' => $channel['channel_account_id'], 'channel_id' => $channel['channel_id'], 'posturl' => $hub['hubloc_callback'], + 'driver' => $hub['hubloc_network'], 'notify' => $n, 'msg' => EMPTY_STR )); diff --git a/Zotlabs/Lib/Queue.php b/Zotlabs/Lib/Queue.php index 49891a55b..6acc58bc5 100644 --- a/Zotlabs/Lib/Queue.php +++ b/Zotlabs/Lib/Queue.php @@ -116,7 +116,7 @@ class Queue { dbesc($arr['hash']), intval($arr['account_id']), intval($arr['channel_id']), - dbesc(($arr['driver']) ? $arr['driver'] : 'zot'), + dbesc(($arr['driver']) ? $arr['driver'] : 'zot6'), dbesc($arr['posturl']), intval(1), intval(($arr['priority']) ? $arr['priority'] : 0), -- cgit v1.2.3 From a31981966e4916b6a40af0743f4dcb578511d239 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 5 Apr 2020 09:29:23 +0000 Subject: fix warning if iconfig value is an array --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index c50606d4f..3c16a5367 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -512,7 +512,7 @@ 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']); + $value = ((is_string($att['v']) && preg_match('|^a:[0-9]+:{.*}$|s', $att['v'])) ? unserialize($att['v']) : $att['v']); $ret[] = [ 'type' => 'PropertyValue', 'name' => 'zot.' . $att['cat'] . '.' . $att['k'], 'value' => $value ]; } } -- cgit v1.2.3 From 328685d2fbe505fd5b1bf9892a0cce993210ac52 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 9 Apr 2020 09:38:36 +0000 Subject: move from build_sync_packet() to Libsync::build_sync_packet() --- Zotlabs/Lib/Apps.php | 6 ++++-- Zotlabs/Lib/Chatroom.php | 4 +++- Zotlabs/Lib/NativeWiki.php | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index 9d60e9eae..d65eed14f 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -2,6 +2,8 @@ namespace Zotlabs\Lib; +use Zotlabs\Lib\Libsync; + require_once('include/plugin.php'); require_once('include/channel.php'); @@ -603,7 +605,7 @@ class Apps { intval(TERM_OBJ_APP), intval($r[0]['id']) ); - build_sync_packet($uid,array('app' => $r[0])); + Libsync::build_sync_packet($uid,array('app' => $r[0])); } } } @@ -669,7 +671,7 @@ class Apps { ); } if(! intval($x[0]['app_system'])) { - build_sync_packet($uid,array('app' => $x)); + Libsync::build_sync_packet($uid,array('app' => $x)); } } else { diff --git a/Zotlabs/Lib/Chatroom.php b/Zotlabs/Lib/Chatroom.php index 882c846cd..34853b6ab 100644 --- a/Zotlabs/Lib/Chatroom.php +++ b/Zotlabs/Lib/Chatroom.php @@ -1,6 +1,8 @@ $r)); + Libsync::build_sync_packet($channel['channel_id'],array('chatroom' => $r)); q("delete from chatroom where cr_id = %d", intval($r[0]['cr_id']) diff --git a/Zotlabs/Lib/NativeWiki.php b/Zotlabs/Lib/NativeWiki.php index 662fddad0..6bda76eee 100644 --- a/Zotlabs/Lib/NativeWiki.php +++ b/Zotlabs/Lib/NativeWiki.php @@ -2,6 +2,8 @@ namespace Zotlabs\Lib; +use Zotlabs\Lib\Libsync; + define ( 'NWIKI_ITEM_RESOURCE_TYPE', 'nwiki' ); class NativeWiki { @@ -178,7 +180,7 @@ class NativeWiki { foreach($sync_item as $w) { $pkt[] = encode_item($w,true); } - build_sync_packet($uid,array('wiki' => $pkt)); + Libsync::build_sync_packet($uid,array('wiki' => $pkt)); } } } -- cgit v1.2.3 From 6de823b532fc526a321e6b2b4df2cdd6175b7eb7 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 12 Apr 2020 08:59:42 +0000 Subject: discover_feed() does not exist yet --- Zotlabs/Lib/Connect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php index 5fc0e3fe1..caac30f7a 100644 --- a/Zotlabs/Lib/Connect.php +++ b/Zotlabs/Lib/Connect.php @@ -97,7 +97,7 @@ class Connect { $feeds = get_config('system','feed_contacts'); if (($feeds) && (in_array($protocol, [ '', 'feed', 'rss' ]))) { - $d = discover_feed($url); + $d = discover_by_url($url); } else { $result['message'] = t('Remote channel or protocol unavailable.'); -- cgit v1.2.3 From d6b9c8b93d5f04d986b1c9e61be9146d556f403a Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 15 Apr 2020 08:43:28 +0000 Subject: =?UTF-8?q?=C3=83fix=20php=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zotlabs/Lib/ThreadItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index dee7cda56..a5dd81d40 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -113,7 +113,7 @@ class ThreadItem { if(intval($item['item_private']) && ($item['owner']['xchan_network'] === 'activitypub')) { $recips = get_iconfig($item['parent'], 'activitypub', 'recips'); - if(! in_array($observer['xchan_url'], $recips['to'])) + if(! is_array($recips['to']) || ! in_array($observer['xchan_url'], $recips['to'])) $privacy_warning = true; } -- cgit v1.2.3 From 91cad21d332154eba17b21d3a2dd6a64d55d0a28 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 15 Apr 2020 11:56:56 +0000 Subject: fetch the item for asld in Lib/Share. This probably fixes addons issue #146 --- Zotlabs/Lib/Share.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Share.php b/Zotlabs/Lib/Share.php index 3a2ab1783..f8b636c10 100644 --- a/Zotlabs/Lib/Share.php +++ b/Zotlabs/Lib/Share.php @@ -2,6 +2,7 @@ namespace Zotlabs\Lib; +use Zotlabs\Lib\Activity; class Share { @@ -54,7 +55,7 @@ class Share { if(! $this->item) return $obj; - $obj['asld'] = $this->item['mid']; + $obj['asld'] = Activity::fetch_item( [ 'id' => $this->item['mid'] ] ); $obj['type'] = $this->item['obj_type']; $obj['id'] = $this->item['mid']; $obj['content'] = $this->item['body']; -- cgit v1.2.3 From 223c4c7b9a01f70106e0ae0b72da4a13235af56c Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 09:23:48 +0000 Subject: implement addressing and fix conversation fetching --- Zotlabs/Lib/Activity.php | 210 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 186 insertions(+), 24 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 3c16a5367..2ba693049 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -419,7 +419,71 @@ class Activity { $ret['attachment'] = $a; } + $public = (($i['item_private']) ? false : true); + $top_level = (($i['mid'] === $i['parent_mid']) ? true : false); + + if ($public) { + $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; + $ret['cc'] = [ z_root() . '/followers/' . substr($i['author']['xchan_addr'],0,strpos($i['author']['xchan_addr'],'@')) ]; + } + else { + + // private activity + + if ($top_level) { + $ret['to'] = self::map_acl($i); + } + else { + $ret['to'] = []; + if ($ret['tag']) { + foreach ($ret['tag'] as $mention) { + if (is_array($mention) && array_key_exists('href',$mention) && $mention['href']) { + $h = q("select * from hubloc where hubloc_id_url = '%s' limit 1", + dbesc($mention['href']) + ); + if ($h) { + if ($h[0]['hubloc_network'] === 'activitypub') { + $addr = $h[0]['hubloc_hash']; + } + else { + $addr = $h[0]['hubloc_id_url']; + } + if (! in_array($addr,$ret['to'])) { + $ret['to'][] = $addr; + } + } + } + } + } + $d = q("select hubloc.* from hubloc left join item on hubloc_hash = owner_xchan where item.id = %d limit 1", + intval($i['parent']) + ); + if ($d) { + if ($d[0]['hubloc_network'] === 'activitypub') { + $addr = $d[0]['hubloc_hash']; + } + else { + $addr = $d[0]['hubloc_id_url']; + } + if (! in_array($addr,$ret['to'])) { + $ret['cc'][] = $addr; + } + } + } + } + + $mentions = self::map_mentions($i); + if (count($mentions) > 0) { + if (! $ret['to']) { + $ret['to'] = $mentions; + } + else { + $ret['to'] = array_values(array_unique(array_merge($ret['to'], $mentions))); + } + } + return $ret; + } static function decode_taxonomy($item) { @@ -756,57 +820,155 @@ class Activity { return []; } + $t = self::encode_taxonomy($i); + if ($t) { + $ret['tag'] = $t; + } + + // addressing madness + + $public = (($i['item_private']) ? false : true); + $top_level = (($reply) ? false : true); + + if ($public) { + $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; + $ret['cc'] = [ z_root() . '/followers/' . substr($i['author']['xchan_addr'],0,strpos($i['author']['xchan_addr'],'@')) ]; + } + else { + + // private activity + + if ($top_level) { + $ret['to'] = self::map_acl($i); + } + else { + $ret['to'] = []; + if ($ret['tag']) { + foreach ($ret['tag'] as $mention) { + if (is_array($mention) && array_key_exists('href',$mention) && $mention['href']) { + $h = q("select * from hubloc where hubloc_id_url = '%s' limit 1", + dbesc($mention['href']) + ); + if ($h) { + if ($h[0]['hubloc_network'] === 'activitypub') { + $addr = $h[0]['hubloc_hash']; + } + else { + $addr = $h[0]['hubloc_id_url']; + } + if (! in_array($addr,$ret['to'])) { + $ret['to'][] = $addr; + } + } + } + } + } + + $d = q("select hubloc.* from hubloc left join item on hubloc_hash = owner_xchan where item.id = %d limit 1", + intval($i['parent']) + ); + if ($d) { + if ($d[0]['hubloc_network'] === 'activitypub') { + $addr = $d[0]['hubloc_hash']; + } + else { + $addr = $d[0]['hubloc_id_url']; + } + if (! in_array($addr,$ret['to'])) { + $ret['cc'][] = $addr; + } + } + } + } + + $mentions = self::map_mentions($i); + if (count($mentions) > 0) { + if (! $ret['to']) { + $ret['to'] = $mentions; + } + else { + $ret['to'] = array_values(array_unique(array_merge($ret['to'], $mentions))); + } + } + return $ret; } + // Returns an array of URLS for any mention tags found in the item array $i. + static function map_mentions($i) { - if(! $i['term']) { + + if (! $i['term']) { return []; } $list = []; foreach ($i['term'] as $t) { - if($t['ttype'] == TERM_MENTION) { - $list[] = $t['url']; + if (! $t['url']) { + continue; + } + if ($t['ttype'] == TERM_MENTION) { + $url = self::lookup_term_url($t['url']); + $list[] = (($url) ? $url : $t['url']); } } return $list; } - static function map_acl($i,$mentions = false) { + // Returns an array of all recipients targeted by private item array $i. - $private = false; - $list = []; - $x = collect_recipients($i,$private); - if($x) { - stringify_array_elms($x); - if(! $x) - return; - - $strict = (($mentions) ? true : get_config('activitypub','compliance')); + static function map_acl($i) { + $ret = []; - $sql_extra = (($strict) ? " and xchan_network = 'activitypub' " : ''); + if (! $i['item_private']) { + return $ret; + } - $details = q("select xchan_url, xchan_addr, xchan_name from xchan where xchan_hash in (" . implode(',',$x) . ") $sql_extra"); + if ($i['allow_gid']) { + $tmp = expand_acl($i['allow_gid']); + if ($tmp) { + foreach ($tmp as $t) { + $ret[] = z_root() . '/lists/' . $t; + } + } + } - if($details) { - foreach($details as $d) { - if($mentions) { - $list[] = [ 'type' => 'Mention', 'href' => $d['xchan_url'], 'name' => '@' . (($d['xchan_addr']) ? $d['xchan_addr'] : $d['xchan_name']) ]; - } - else { - $list[] = $d['xchan_url']; + if ($i['allow_cid']) { + $tmp = expand_acl($i['allow_cid']); + $list = stringify_array($tmp,true); + if ($list) { + $details = q("select hubloc_id_url from hubloc where hubloc_hash in (" . $list . ") "); + if ($details) { + foreach ($details as $d) { + $ret[] = $d['hubloc_id_url']; } } } } - return $list; - + return $ret; } + static function lookup_term_url($url) { + + // The xchan_url for mastodon is a text/html rendering. This is called from map_mentions where we need + // to convert the mention url to an ActivityPub id. If this fails for any reason, return the url we have + + $r = q("select * from hubloc where hubloc_id_url = '%s' limit 1", + dbesc($url) + ); + + if ($r) { + if ($r[0]['hubloc_network'] === 'activitypub') { + return $r[0]['hubloc_hash']; + } + return $r[0]['hubloc_id_url']; + } + + return $url; + } static function encode_person($p, $extended = true) { -- cgit v1.2.3 From 3d5fdd086be63bb8e9a889bfe593b3aaa4b4a6a2 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 11:30:19 +0000 Subject: only return hublocs with hubloc_id_url set --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 2ba693049..24214072a 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -939,7 +939,7 @@ class Activity { $tmp = expand_acl($i['allow_cid']); $list = stringify_array($tmp,true); if ($list) { - $details = q("select hubloc_id_url from hubloc where hubloc_hash in (" . $list . ") "); + $details = q("select hubloc_id_url from hubloc where hubloc_hash in (" . $list . ") and hubloc_id_url != ''"); if ($details) { foreach ($details as $d) { $ret[] = $d['hubloc_id_url']; -- cgit v1.2.3 From 4cfc0b1a6410193b65673c5d43180aa9cecaeea2 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 12:19:34 +0000 Subject: de-duplicate $post_tags --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 24214072a..5882a0777 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -890,7 +890,7 @@ class Activity { $ret['to'] = array_values(array_unique(array_merge($ret['to'], $mentions))); } } - +hz_syslog(print_r($ret,true)); return $ret; } -- cgit v1.2.3 From 602ca91700fa314265b4f65a04465347e68f53db Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 13:17:37 +0000 Subject: remove debug code --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 5882a0777..24214072a 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -890,7 +890,7 @@ class Activity { $ret['to'] = array_values(array_unique(array_merge($ret['to'], $mentions))); } } -hz_syslog(print_r($ret,true)); + return $ret; } -- cgit v1.2.3 From c7fdc5379595d8829f916032c73f3126abfd37b4 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 13:59:30 +0000 Subject: more do not include hublocs with no hubloc_id_url --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 24214072a..f3421c3fa 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -956,7 +956,7 @@ class Activity { // The xchan_url for mastodon is a text/html rendering. This is called from map_mentions where we need // to convert the mention url to an ActivityPub id. If this fails for any reason, return the url we have - $r = q("select * from hubloc where hubloc_id_url = '%s' limit 1", + $r = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_id_url != '' limit 1", dbesc($url) ); -- cgit v1.2.3 From 109f9eed611949bdd1d03183e8e05d1236a38ac7 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 14:09:08 +0000 Subject: just fetch the info we need --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index f3421c3fa..f80f71a74 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -956,7 +956,7 @@ class Activity { // The xchan_url for mastodon is a text/html rendering. This is called from map_mentions where we need // to convert the mention url to an ActivityPub id. If this fails for any reason, return the url we have - $r = q("select * from hubloc where hubloc_id_url = '%s' and hubloc_id_url != '' limit 1", + $r = q("select hubloc_network, hubloc_hash, hubloc_id_url from hubloc where hubloc_id_url = '%s' and hubloc_id_url != '' limit 1", dbesc($url) ); -- cgit v1.2.3 From 42631b5943551d025c95e0b76e85471f4bde7101 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 18 Apr 2020 14:22:40 +0000 Subject: revert --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index f80f71a74..613f939ab 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -956,7 +956,7 @@ class Activity { // The xchan_url for mastodon is a text/html rendering. This is called from map_mentions where we need // to convert the mention url to an ActivityPub id. If this fails for any reason, return the url we have - $r = q("select hubloc_network, hubloc_hash, hubloc_id_url from hubloc where hubloc_id_url = '%s' and hubloc_id_url != '' limit 1", + $r = q("select hubloc_network, hubloc_hash, hubloc_id_url from hubloc where hubloc_id_url = '%s' limit 1", dbesc($url) ); -- cgit v1.2.3 From 244936b0fd3ac60defa9fa6042e6ee3be869721c Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 20 Apr 2020 09:34:00 +0000 Subject: some work on improving federation of item_private and make sure we deal with an array in array_path_exists() --- Zotlabs/Lib/Activity.php | 9 +++++++-- Zotlabs/Lib/ActivityStreams.php | 13 +++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 613f939ab..322579610 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2339,8 +2339,13 @@ class Activity { $s['plink'] = $s['mid']; } - if ($act->recips && (! in_array(ACTIVITY_PUBLIC_INBOX,$act->recips))) - $s['item_private'] = 1; + // assume this is private unless specifically told otherwise. + + $s['item_private'] = 1; + + if ($act->recips && in_array(ACTIVITY_PUBLIC_INBOX, $act->recips)) { + $s['item_private'] = 0; + } if (is_array($act->obj)) { if (array_key_exists('directMessage',$act->obj) && intval($act->obj['directMessage'])) { diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index d8bd72943..b1ef59364 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -146,15 +146,20 @@ class ActivityStreams { */ function collect_recips($base = '', $namespace = '') { $x = []; + $fields = [ 'to', 'cc', 'bto', 'bcc', 'audience']; foreach($fields as $f) { $y = $this->get_compound_property($f, $base, $namespace); if($y) { - $x = array_merge($x, $y); - if(! is_array($this->raw_recips)) + if (! is_array($this->raw_recips)) { $this->raw_recips = []; + } - $this->raw_recips[$f] = $x; + if (! is_array($y)) { + $y = [ $y ]; + } + $this->raw_recips[$f] = $y; + $x = array_merge($x, $y); } } // not yet ready for prime time @@ -411,4 +416,4 @@ class ActivityStreams { } -} \ No newline at end of file +} -- cgit v1.2.3 From b7a655917ed1f7caa5b8b3d9b92fdd578c6252c4 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 23 Apr 2020 18:19:25 +0000 Subject: some work on deprecating ACTIVITY_OBJ_FILE --- Zotlabs/Lib/Activity.php | 11 +++++++---- Zotlabs/Lib/Enotify.php | 3 +++ Zotlabs/Lib/NativeWiki.php | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 322579610..9b79190bb 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1131,7 +1131,6 @@ class Activity { 'http://activitystrea.ms/schema/1.0/photo' => 'Image', 'http://activitystrea.ms/schema/1.0/profile-photo' => 'Icon', 'http://activitystrea.ms/schema/1.0/event' => 'Event', - 'http://activitystrea.ms/schema/1.0/wiki' => 'Document', 'http://purl.org/zot/activity/location' => 'Place', 'http://purl.org/zot/activity/chessgame' => 'Game', 'http://purl.org/zot/activity/tagterm' => 'zot:Tag', @@ -1139,7 +1138,10 @@ class Activity { 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', 'Invite' => 'Invite', - 'Question' => 'Question' + 'Question' => 'Question', + 'Document' => 'Document', + 'Audio' => 'Audio', + 'Video' => 'Video' ]; call_hooks('activity_obj_decode_mapper',$objs); @@ -1167,7 +1169,6 @@ class Activity { 'http://activitystrea.ms/schema/1.0/photo' => 'Image', 'http://activitystrea.ms/schema/1.0/profile-photo' => 'Icon', 'http://activitystrea.ms/schema/1.0/event' => 'Event', - 'http://activitystrea.ms/schema/1.0/wiki' => 'Document', 'http://purl.org/zot/activity/location' => 'Place', 'http://purl.org/zot/activity/chessgame' => 'Game', 'http://purl.org/zot/activity/tagterm' => 'zot:Tag', @@ -1175,7 +1176,9 @@ class Activity { 'http://purl.org/zot/activity/file' => 'zot:File', 'http://purl.org/zot/activity/mood' => 'zot:Mood', 'Invite' => 'Invite', - 'Question' => 'Question' + 'Question' => 'Question', + 'Audio' => 'Audio', + 'Video' => 'Video' ]; call_hooks('activity_obj_mapper',$objs); diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 85e90d67c..a4fc8aa75 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -818,6 +818,9 @@ class Enotify { $itemem_text = sprintf( t('repeated %s\'s post'), '[bdi]' . $item['author']['xchan_name'] . '[/bdi]'); } + if(in_array($item['obj_type'], ['Document', 'Video', 'Audio', 'Image'])) { + $itemem_text = t('shared a file with you'); + } } $edit = false; diff --git a/Zotlabs/Lib/NativeWiki.php b/Zotlabs/Lib/NativeWiki.php index 6bda76eee..3ec032075 100644 --- a/Zotlabs/Lib/NativeWiki.php +++ b/Zotlabs/Lib/NativeWiki.php @@ -73,7 +73,7 @@ class NativeWiki { $arr['item_thread_top'] = 1; $arr['item_private'] = intval($acl->is_private()); $arr['verb'] = ACTIVITY_CREATE; - $arr['obj_type'] = ACTIVITY_OBJ_WIKI; + $arr['obj_type'] = 'Document'; $arr['body'] = '[table][tr][td][h1]New Wiki[/h1][/td][/tr][tr][td][zrl=' . $wiki_url . ']' . $wiki['htmlName'] . '[/zrl][/td][/tr][/table]'; $arr['public_policy'] = map_scope(\Zotlabs\Access\PermissionLimits::Get($channel['channel_id'],'view_wiki'),true); -- cgit v1.2.3 From 837dbb7a1414d9e14d588f1e425acd12a2dc87e3 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 29 Apr 2020 11:10:54 +0000 Subject: =?UTF-8?q?=C3=83fix=20photo=20items?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zotlabs/Lib/Activity.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9b79190bb..5c72a1175 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -178,7 +178,6 @@ class Activity { static function fetch_image($x) { - $ret = [ 'type' => 'Image', 'id' => $x['id'], @@ -2242,9 +2241,7 @@ class Activity { } - // avoid double images from hubzilla to zap/osada - - if($act->obj['type'] === 'Image' && strpos($s['body'],'zrl=') === false) { + if($act->obj['type'] === 'Image') { $ptr = null; @@ -2258,10 +2255,11 @@ class Activity { } foreach($ptr as $vurl) { if(strpos($s['body'],$vurl['href']) === false) { - $s['body'] .= '[zmg]' . $vurl['href'] . '[/zmg]' . "\n\n" . $s['body']; + $bb_imgs .= '[zmg]' . $vurl['href'] . '[/zmg]' . "\n\n"; break; } } + $s['body'] = $bb_imgs . $s['body']; } elseif(is_string($act->obj['url'])) { if(strpos($s['body'],$act->obj['url']) === false) { -- cgit v1.2.3 From f4a71db42dec1daa5d3cbf305372bdf47b4add5f Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Sat, 2 May 2020 17:28:49 +0200 Subject: Display delayed posts on author's channel page --- Zotlabs/Lib/ThreadItem.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index a5dd81d40..426f88688 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -426,6 +426,7 @@ class ThreadItem { 'editedtime' => (($item['edited'] != $item['created']) ? sprintf( t('last edited: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r')) : ''), 'expiretime' => (($item['expires'] > NULL_DATE) ? sprintf( t('Expires: %s'), datetime_convert('UTC', date_default_timezone_get(), $item['expires'], 'r')):''), 'lock' => $lock, + 'delayed' => $item['item_delayed'], 'privacy_warning' => $privacy_warning, 'verified' => $verified, 'unverified' => $unverified, @@ -460,7 +461,7 @@ class ThreadItem { 'tagger' => ((feature_enabled($conv->get_profile_owner(),'commtag')) ? $tagger : ''), 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing') && ($item['item_type'] == ITEM_TYPE_POST)) ? $filer : ''), 'pinned' => ($pinned ? t('Pinned post') : ''), - 'pinnable' => (($this->is_toplevel() && local_channel() && $item['owner_xchan'] == $observer['xchan_hash'] && $allowed_type && $item['item_private'] == 0) ? '1' : ''), + 'pinnable' => (($this->is_toplevel() && local_channel() && $item['owner_xchan'] == $observer['xchan_hash'] && $allowed_type && $item['item_private'] == 0 && $item['item_delayed'] == 0) ? '1' : ''), 'pinme' => ($pinned ? t('Unpin from the top') : t('Pin to the top')), 'bookmark' => (($conv->get_profile_owner() == local_channel() && local_channel() && $has_bookmarks) ? t('Save Bookmarks') : ''), 'addtocal' => (($has_event) ? t('Add to Calendar') : ''), @@ -488,7 +489,7 @@ class ThreadItem { 'modal_dismiss' => t('Close'), 'showlike' => $showlike, 'showdislike' => $showdislike, - 'comment' => $this->get_comment_box($indent), + 'comment' => ($item['item_delayed'] ? '' : $this->get_comment_box($indent)), 'previewing' => ($conv->is_preview() ? true : false ), 'preview_lbl' => t('This is an unsaved preview'), 'wait' => t('Please wait'), -- cgit v1.2.3 From 06d1cf83d2b1acfef5529fe388d2502bea381881 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 5 May 2020 14:51:00 +0000 Subject: deal with polls and votes in enotify --- Zotlabs/Lib/Enotify.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index a4fc8aa75..f706b0fb9 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -143,19 +143,26 @@ class Enotify { $action = t('commented on'); - if(array_key_exists('item',$params) && in_array($params['item']['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { + if(array_key_exists('item',$params)) { - if(! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) { - logger('notification: not a visible activity. Ignoring.'); - pop_lang(); - return; - } + if(in_array($params['item']['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) { - if(activity_match($params['verb'], ACTIVITY_LIKE)) - $action = t('liked'); + if(! $always_show_in_notices || !($vnotify & VNOTIFY_LIKE)) { + logger('notification: not a visible activity. Ignoring.'); + pop_lang(); + return; + } + + if(activity_match($params['verb'], ACTIVITY_LIKE)) + $action = t('liked'); + + if(activity_match($params['verb'], ACTIVITY_DISLIKE)) + $action = t('disliked'); + + } - if(activity_match($params['verb'], ACTIVITY_DISLIKE)) - $action = t('disliked'); + if($params['item']['obj_type'] === 'Answer') + $action = t('voted on'); } -- cgit v1.2.3 From a04b6d178bd4a5facc827c6ac3b9a51b1a0c88d9 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 7 May 2020 07:55:05 +0000 Subject: deprecate premium channel app --- Zotlabs/Lib/Apps.php | 1 - 1 file changed, 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index d65eed14f..f11bb9628 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -372,7 +372,6 @@ class Apps { 'OAuth2 Apps Manager' => t('OAuth2 Apps Manager'), 'PDL Editor' => t('PDL Editor'), 'Permission Categories' => t('Permission Categories'), - 'Premium Channel' => t('Premium Channel'), 'Public Stream' => t('Public Stream'), 'My Chatrooms' => t('My Chatrooms'), 'Channel Export' => t('Channel Export') -- cgit v1.2.3 From f473b5abfbbac4a6cadaf6fc26ed5fd950987ed6 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 May 2020 07:53:21 +0000 Subject: as_vid_sort -> vid_sort --- Zotlabs/Lib/Activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 5c72a1175..2b88b6683 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1597,7 +1597,7 @@ class Activity { // sort function width decreasing - static function as_vid_sort($a,$b) { + static function vid_sort($a,$b) { if($a['width'] === $b['width']) return 0; return (($a['width'] > $b['width']) ? -1 : 1); @@ -1767,7 +1767,7 @@ class Activity { } } if($mps) { - usort($mps,'as_vid_sort'); + usort($mps,[ __CLASS__, 'vid_sort' ]); foreach($mps as $m) { if(intval($m['width']) < 500) { $s['body'] .= "\n\n" . '[video]' . $m['href'] . '[/video]'; -- cgit v1.2.3 From 3d02758fee664a67c8f15f4a7a885ae629d90cf0 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 10 May 2020 10:55:57 +0000 Subject: deal with diaspora uuid --- Zotlabs/Lib/Activity.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 2b88b6683..3287dd6fb 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -346,6 +346,7 @@ class Activity { $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid'])); + $ret['diaspora:guid'] = $i['uuid']; if($i['title']) $ret['name'] = $i['title']; @@ -1662,6 +1663,7 @@ class Activity { $s['aid'] = $channel['channel_account_id']; $s['uid'] = $channel['channel_id']; $s['mid'] = urldecode($act->obj['id']); + $s['uuid'] = $act->obj['diaspora:guid']; $s['plink'] = urldecode($act->obj['id']); @@ -1953,6 +1955,7 @@ class Activity { self::actor_store($act->actor['id'],$act->actor); $s['mid'] = $act->obj['id']; + $s['uuid'] = $act->obj['diaspora:guid']; $s['parent_mid'] = $act->parent_id; if($act->data['published']) { @@ -2400,11 +2403,6 @@ class Activity { $item['aid'] = $channel['channel_account_id']; $item['uid'] = $channel['channel_id']; - $s['uuid'] = ''; - - // Friendica sends the diaspora guid in a nonstandard field via AP - if($act->obj['diaspora:guid']) - $s['uuid'] = $act->obj['diaspora:guid']; if(! ( $item['author_xchan'] && $item['owner_xchan'])) { logger('owner or author missing.'); -- cgit v1.2.3 From 22d8523e76f45532aa874eb2da78d9956e4b165e Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 12 May 2020 08:23:41 +0000 Subject: DB update 1238 to fix hubloc_id_url for existing hublocs and set hubloc_id_url in Activity::actor_store() --- Zotlabs/Lib/Activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 3287dd6fb..4b7ed30f3 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1548,7 +1548,8 @@ class Activity { 'hubloc_host' => $hostname, 'hubloc_callback' => $inbox, 'hubloc_updated' => datetime_convert(), - 'hubloc_primary' => 1 + 'hubloc_primary' => 1, + 'hubloc_id_url' => $profile ] ); } -- cgit v1.2.3 From 81338e80865caff4c911980c0cb9689cb10c7087 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 15 May 2020 10:10:07 +0000 Subject: use zot_record_preferred() when fetching keys --- Zotlabs/Lib/JSalmon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/JSalmon.php b/Zotlabs/Lib/JSalmon.php index bed748432..67512046f 100644 --- a/Zotlabs/Lib/JSalmon.php +++ b/Zotlabs/Lib/JSalmon.php @@ -69,4 +69,4 @@ class JSalmon { } -} \ No newline at end of file +} -- cgit v1.2.3 From b6efb02ed291fcdfb32e8587a031950d752327bc Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 15 May 2020 15:08:57 +0000 Subject: uuid for likes --- Zotlabs/Lib/Activity.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 4b7ed30f3..5b387e6ee 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -708,6 +708,8 @@ class Activity { $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/activity/' . urlencode($i['mid'])); } + $ret['diaspora:guid'] = $i['uuid']; + if($i['title']) $ret['name'] = html2plain(bbcode($i['title'], [ 'cache' => true ])); @@ -1983,6 +1985,7 @@ class Activity { $response_activity = true; $s['mid'] = $act->id; + $s['uuid'] = $act['diaspora:guid']; $s['parent_mid'] = $act->obj['id']; // over-ride the object timestamp with the activity -- cgit v1.2.3 From e3aaa39f9eb62a292c81956b92cb71a47ffc075c Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 15 May 2020 15:26:05 +0000 Subject: Revert "uuid for likes" This reverts commit b6efb02ed291fcdfb32e8587a031950d752327bc. --- Zotlabs/Lib/Activity.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 5b387e6ee..4b7ed30f3 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -708,8 +708,6 @@ class Activity { $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/activity/' . urlencode($i['mid'])); } - $ret['diaspora:guid'] = $i['uuid']; - if($i['title']) $ret['name'] = html2plain(bbcode($i['title'], [ 'cache' => true ])); @@ -1985,7 +1983,6 @@ class Activity { $response_activity = true; $s['mid'] = $act->id; - $s['uuid'] = $act['diaspora:guid']; $s['parent_mid'] = $act->obj['id']; // over-ride the object timestamp with the activity -- cgit v1.2.3 From 13319985fda0a67e1fb67cf521f6a3ea3b0aebac Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 15 May 2020 19:28:03 +0200 Subject: uuid for likes --- Zotlabs/Lib/Activity.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 4b7ed30f3..014ff8949 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -708,6 +708,8 @@ class Activity { $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/activity/' . urlencode($i['mid'])); } + $ret['diaspora:guid'] = $i['uuid']; + if($i['title']) $ret['name'] = html2plain(bbcode($i['title'], [ 'cache' => true ])); @@ -1984,6 +1986,7 @@ class Activity { $s['mid'] = $act->id; $s['parent_mid'] = $act->obj['id']; + $s['uuid'] = $act->{'diaspora:guid'}; // over-ride the object timestamp with the activity -- cgit v1.2.3 From 3201a4bec5f3524c2eba813e46d69b4c5943840f Mon Sep 17 00:00:00 2001 From: Zot Date: Thu, 11 Jun 2020 12:13:43 +0200 Subject: allow apps to be both pinned and starred independently --- Zotlabs/Lib/Apps.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index f11bb9628..7b980b8d3 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -564,7 +564,8 @@ class Apps { '$featured' => ((strpos($papp['categories'], 'nav_featured_app') === false) ? false : true), '$pinned' => ((strpos($papp['categories'], 'nav_pinned_app') === false) ? false : true), '$navapps' => (($mode == 'nav') ? true : false), - '$order' => (($mode == 'nav-order') ? true : false), + '$order' => (($mode === 'nav-order' || $mode === 'nav-order-pinned') ? true : false), + '$mode' => $mode, '$add' => t('Add to app-tray'), '$remove' => t('Remove from app-tray'), '$add_nav' => t('Pin to navbar'), @@ -959,9 +960,6 @@ class Apps { if($list) { foreach($list as $li) { $papp = self::app_encode($li); - if($menu !== 'nav_pinned_app' && strpos($papp['categories'],'nav_pinned_app') !== false) - continue; - $syslist[] = $papp; } } -- cgit v1.2.3 From 8cd66145bdd8bf0f43c2a1774181c974335fc494 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 14 Jun 2020 15:38:44 +0200 Subject: fix discovery --- Zotlabs/Lib/Libzot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 5e212ad70..dda6d5d95 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -2908,7 +2908,7 @@ class Libzot { ]; $ret['channel_role'] = get_pconfig($e['channel_id'],'system','permissions_role','custom'); - $ret['protocols'] = [ 'zot', 'zot6' ]; + $ret['protocols'] = [ 'zot6', 'zot' ]; $ret['searchable'] = $searchable; $ret['adult_content'] = $adult_channel; $ret['public_forum'] = $public_forum; -- cgit v1.2.3 From fa752b0ac1bf4c0b19fcb0f7ff7dcfa3b3b90078 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Sun, 12 Jul 2020 19:06:24 -0700 Subject: zot6 group updates to support edit and delete of top-level group posts. This is supported remotely by editing or removing the post that started it all. A W2W post can only be deleted at this time. --- Zotlabs/Lib/ThreadItem.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index 426f88688..fadc38b38 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -150,9 +150,11 @@ class ThreadItem { $edpost = false; - if($observer['xchan_hash'] == $this->get_data_value('author_xchan') + if($observer && $observer['xchan_hash'] + && ($observer['xchan_hash'] == $this->get_data_value('author_xchan') || $observer['xchan_hash'] == $this->get_data_value('owner_xchan') - || $this->get_data_value('uid') == local_channel()) + || $observer['xchan_hash'] == $this->get_data_value('source_xchan') + || $this->get_data_value('uid') == local_channel())) $dropping = true; -- cgit v1.2.3 From 774cc852d4bc46a533c5ec2fb533463871721fe0 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 13 Jul 2020 09:18:11 +0000 Subject: fix php warning --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 014ff8949..d883eac67 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3042,7 +3042,7 @@ class Activity { } } - if (array_key_exists('source',$act) && array_key_exists('mediaType',$act['source'])) { + if (array_path_exists('source/mediaType',$act) && array_path_exists('source/content',$act)) { if ($act['source']['mediaType'] === 'text/bbcode') { $content['bbcode'] = purify_html($act['source']['content']); } -- cgit v1.2.3 From 4f95b44ff239f92574491b3053b7f5aace6432d3 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 21 Jul 2020 17:29:40 +0000 Subject: zot6 testing --- Zotlabs/Lib/Activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index d883eac67..5297c1f95 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -20,7 +20,7 @@ class Activity { if(is_array($x)) { - if(array_key_exists('asld',$x)) { + if(array_key_exists('asld',$x) && is_array($x['asld'])) { return $x['asld']; } @@ -165,6 +165,7 @@ class Activity { $r = q("select * from item where mid = '%s' limit 1", dbesc($x['id']) ); + if($r) { xchan_query($r,true); $r = fetch_post_tags($r,true); -- cgit v1.2.3 From ca969cd0ed53563e6b5d518838e4da75f9f3e893 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 21 Jul 2020 17:54:14 +0000 Subject: =?UTF-8?q?those=20are=20not=20l=C3=83ikely=20to=20be=20parents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zotlabs/Lib/Activity.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 5297c1f95..698556001 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2562,8 +2562,8 @@ class Activity { switch($a->type) { case 'Create': case 'Update': - case 'Like': - case 'Dislike': + //case 'Like': + //case 'Dislike': case 'Announce': $item = self::decode_note($a); break; -- cgit v1.2.3 From dd2ffae8bf913e686bb700624154f9176489396d Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 21 Jul 2020 19:08:03 +0000 Subject: Revert "zot6 testing" This reverts commit 4f95b44ff239f92574491b3053b7f5aace6432d3. --- Zotlabs/Lib/Activity.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 698556001..b8432f95a 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -20,7 +20,7 @@ class Activity { if(is_array($x)) { - if(array_key_exists('asld',$x) && is_array($x['asld'])) { + if(array_key_exists('asld',$x)) { return $x['asld']; } @@ -165,7 +165,6 @@ class Activity { $r = q("select * from item where mid = '%s' limit 1", dbesc($x['id']) ); - if($r) { xchan_query($r,true); $r = fetch_post_tags($r,true); -- cgit v1.2.3 From fba64e9451dcc4831b83161ab77301db551f8c17 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 26 Jul 2020 07:16:06 +0000 Subject: improve profile detection and reduce feed result set --- Zotlabs/Lib/Activity.php | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index b8432f95a..25f19510d 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1456,11 +1456,35 @@ class Activity { $icon = $person_obj['icon']; } - if(is_array($person_obj['url']) && array_key_exists('href', $person_obj['url'])) - $profile = $person_obj['url']['href']; - else - $profile = $url; + $links = false; + $profile = false; + + if (is_array($person_obj['url'])) { + if (! array_key_exists(0,$person_obj['url'])) { + $links = [ $person_obj['url'] ]; + } + else { + $links = $person_obj['url']; + } + } + + if ($links) { + foreach ($links as $link) { + if (array_key_exists('mediaType',$link) && $link['mediaType'] === 'text/html') { + $profile = $link['href']; + } + } + if (! $profile) { + $profile = $links[0]['href']; + } + } + elseif (isset($person_obj['url']) && is_string($person_obj['url'])) { + $profile = $person_obj['url']; + } + if (! $profile) { + $profile = $url; + } $inbox = $person_obj['inbox']; @@ -1492,6 +1516,7 @@ class Activity { ); if(! $r) { // create a new record + $r = xchan_store_lowlevel( [ 'xchan_hash' => $url, -- cgit v1.2.3 From e31903cbc9fd9d1230fb4472f25f03f493e79629 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 29 Jul 2020 19:53:00 +0000 Subject: add some context to the notifications --- Zotlabs/Lib/Enotify.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index f706b0fb9..90c498d78 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -856,11 +856,11 @@ class Enotify { 'photo' => $item[$who]['xchan_photo_s'], 'when' => (($edit) ? datetime_convert('UTC', date_default_timezone_get(), $item['edited']) : datetime_convert('UTC', date_default_timezone_get(), $item['created'])), 'class' => (intval($item['item_unseen']) ? 'notify-unseen' : 'notify-seen'), - 'b64mid' => 'b64.' . base64url_encode($item['mid']), + 'b64mid' => (($item['mid']) ? 'b64.' . base64url_encode($item['mid']) : ''), //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), - 'notify_id' => 'undefined', 'thread_top' => (($item['item_thread_top']) ? true : false), 'message' => bbcode(escape_tags($itemem_text)), + 'body' => htmlentities(html2plain(bbcode($item['body'])), ENT_COMPAT, 'UTF-8', false), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], 'uid' => $item['uid'], @@ -885,7 +885,6 @@ class Enotify { $mid = basename($tt['link']); $b64mid = ((strpos($mid, 'b64.') === 0) ? $mid : 'b64.' . base64url_encode($mid)); - $x = [ 'notify_link' => z_root() . '/notify/view/' . $tt['id'], 'name' => $tt['xname'], @@ -893,8 +892,8 @@ class Enotify { 'photo' => $tt['photo'], 'when' => datetime_convert('UTC', date_default_timezone_get(), $tt['created']), 'hclass' => (($tt['seen']) ? 'notify-seen' : 'notify-unseen'), - 'b64mid' => (($tt['otype'] == 'item') ? $b64mid : 'undefined'), - 'notify_id' => (($tt['otype'] == 'item') ? $tt['id'] : 'undefined'), + 'b64mid' => (($tt['otype'] == 'item') ? $b64mid : ''), + 'notify_id' => (($tt['otype'] == 'item') ? $tt['id'] : ''), 'message' => $message ]; @@ -980,8 +979,7 @@ class Enotify { $x = [ 'notify_link' => z_root() . '/admin/accounts', 'name' => $rr['account_email'], - 'addr' => $rr['account_email'], - 'url' => '', + //'addr' => $rr['account_email'], 'photo' => z_root() . '/' . get_default_profile_photo(48), 'when' => datetime_convert('UTC', date_default_timezone_get(),$rr['account_created']), 'hclass' => ('notify-unseen'), -- cgit v1.2.3 From 976d6baf6a0ea5a2dfb692720adddb7b9e53a10c Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 30 Jul 2020 08:48:02 +0000 Subject: use the compact view in html2plain() --- Zotlabs/Lib/Enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 90c498d78..03a824b9b 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -860,7 +860,7 @@ class Enotify { //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'thread_top' => (($item['item_thread_top']) ? true : false), 'message' => bbcode(escape_tags($itemem_text)), - 'body' => htmlentities(html2plain(bbcode($item['body'])), ENT_COMPAT, 'UTF-8', false), + 'body' => htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_COMPAT, 'UTF-8', false), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], 'uid' => $item['uid'], -- cgit v1.2.3 From e55a1a6aa8fe55d20b588f0223a15018053bfd48 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 20 Aug 2020 08:43:13 +0000 Subject: fix item deletion --- Zotlabs/Lib/Activity.php | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 25f19510d..83c04c042 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -314,14 +314,6 @@ class Activity { else { $objtype = self::activity_obj_mapper($i['obj_type']); } - - if(intval($i['item_deleted'])) { - $ret['type'] = 'Tombstone'; - $ret['formerType'] = $objtype; - $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid'])); - return $ret; - } - if ($i['obj']) { $ret = Activity::encode_object($i['obj']); @@ -651,16 +643,36 @@ class Activity { $ret['obj'] = []; } - if(intval($i['item_deleted'])) { - $ret['type'] = 'Tombstone'; - $ret['formerType'] = self::activity_obj_mapper($i['obj_type']); - $ret['id'] = ((strpos($i['mid'],'http') === 0) ? $i['mid'] : z_root() . '/item/' . urlencode($i['mid'])); + if (intval($i['item_deleted'])) { + $ret['type'] = 'Delete'; + $ret['id'] = str_replace('/item/','/activity/',$i['mid']) . '#delete'; $actor = self::encode_person($i['author'],false); - if($actor) + if ($actor) $ret['actor'] = $actor; else return []; + + if ($i['obj']) { + if (! is_array($i['obj'])) { + $i['obj'] = json_decode($i['obj'],true); + } + $obj = self::encode_object($i['obj']); + if ($obj) + $ret['object'] = $obj; + else + return []; + } + else { + $obj = self::encode_item($i); + if ($obj) + $ret['object'] = $obj; + else + return []; + } + + $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; return $ret; + } -- cgit v1.2.3 From c4c47f777724937746c99c064e65f52723443e59 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 20 Aug 2020 22:47:33 +0200 Subject: first cut on implementing additional encryption with the SJCL library. aes only and no backward compatibility. --- Zotlabs/Lib/ThreadStream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php index 020e8729b..f54b3f6c2 100644 --- a/Zotlabs/Lib/ThreadStream.php +++ b/Zotlabs/Lib/ThreadStream.php @@ -23,7 +23,7 @@ class ThreadStream { private $preview = false; private $prepared_item = ''; public $reload = ''; - private $cipher = 'aes256'; + private $cipher = 'AES-256'; // $prepared_item is for use by alternate conversation structures such as photos // wherein we've already prepared a top level item which doesn't look anything like -- cgit v1.2.3 From 49df57df45f82e2e0f1b10f2508f61b78d6d3ac0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Fri, 21 Aug 2020 10:55:55 +0200 Subject: use the default setting and also add the mode to the cipher. aes-128 is to be preferred over aes-256 according to bruce schneier https://www.schneier.com/blog/archives/2009/07/another_new_aes.html#c386957 --- Zotlabs/Lib/ThreadStream.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadStream.php b/Zotlabs/Lib/ThreadStream.php index f54b3f6c2..68b2c70dd 100644 --- a/Zotlabs/Lib/ThreadStream.php +++ b/Zotlabs/Lib/ThreadStream.php @@ -23,7 +23,7 @@ class ThreadStream { private $preview = false; private $prepared_item = ''; public $reload = ''; - private $cipher = 'AES-256'; + private $cipher = 'AES-128-CCM'; // $prepared_item is for use by alternate conversation structures such as photos // wherein we've already prepared a top level item which doesn't look anything like -- cgit v1.2.3 From ff09b2131e6ba7045d5afd65adfd49e427617afc Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 11 Sep 2020 12:11:09 +0000 Subject: disable community tags until we agree on how to implemnt this in zot6/activitypub --- Zotlabs/Lib/ThreadItem.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index fadc38b38..024502d2a 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -287,12 +287,16 @@ class ThreadItem { $settings = ''; + $tagger = []; + // FIXME - check this permission if($conv->get_profile_owner() == local_channel()) { + /* disable until we agree on how to implemnt this in zot6/activitypub $tagger = array( 'tagit' => t("Add Tag"), 'classtagger' => "", ); + */ $settings = t('Conversation Tools'); } -- cgit v1.2.3 From 9c8d73208123a2566aa44db4dfe53201cc8cb3ab Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 19 Sep 2020 19:19:03 +0000 Subject: 5.0RC testing: their_perms should be reset before they are recreated. Otherwise withdrawn permissions will not take effect locally. --- Zotlabs/Lib/Libzot.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index dda6d5d95..f4eb26463 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -316,14 +316,22 @@ class Libzot { $x = self::import_xchan($record['data'], (($force) ? UPDATE_FLAGS_FORCED : UPDATE_FLAGS_UPDATED)); + if(! $x['success']) return false; if($channel && $record['data']['permissions']) { $permissions = explode(',',$record['data']['permissions']); + if($permissions && is_array($permissions)) { $old_read_stream_perm = get_abconfig($channel['channel_id'],$x['hash'],'their_perms','view_stream'); + // We need to reset their_perms prior to setting the new ones. + // Otherwise withdrawn permissions will not take effect locally. + q("DELETE FROM abconfig WHERE chan = %d AND xchan = '%s' AND cat = 'their_perms'", + intval($channel['channel_id']), + dbesc($x['hash']) + ); foreach($permissions as $p) { set_abconfig($channel['channel_id'],$x['hash'],'their_perms',$p,'1'); } -- cgit v1.2.3 From 6f508b81d62f9fec91840d4b7a35eaa5209bdeca Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 23 Sep 2020 11:44:10 +0000 Subject: 5.0RC testing: update hublocs by hubloc_id_url of we mark it deleted or change primary to catch both zot and zot6 hublocs. only set the zot6 hubloc as primary. --- Zotlabs/Lib/Libsync.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index b7cda1770..b16080a51 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -819,9 +819,9 @@ class Libsync { } if(intval($r[0]['hubloc_primary']) && (! $location['primary'])) { - $m = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id = %d", + $m = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id_url = '%s'", dbesc(datetime_convert()), - intval($r[0]['hubloc_id']) + intval($r[0]['hubloc_id_url']) ); $r[0]['hubloc_primary'] = intval($location['primary']); hubloc_change_primary($r[0]); @@ -848,18 +848,18 @@ class Libsync { } } if(intval($r[0]['hubloc_deleted']) && (! intval($location['deleted']))) { - $n = q("update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id = %d", + $n = q("update hubloc set hubloc_deleted = 0, hubloc_updated = '%s' where hubloc_id_url = '%s'", dbesc(datetime_convert()), - intval($r[0]['hubloc_id']) + dbesc($r[0]['hubloc_id_url']) ); $what .= 'undelete_hub '; $changed = true; } elseif((! intval($r[0]['hubloc_deleted'])) && (intval($location['deleted']))) { logger('deleting hubloc: ' . $r[0]['hubloc_addr']); - $n = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d", + $n = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id_url = '%s'", dbesc(datetime_convert()), - intval($r[0]['hubloc_id']) + dbesc($r[0]['hubloc_id_url']) ); $what .= 'delete_hub '; $changed = true; @@ -918,9 +918,9 @@ class Libsync { foreach($xisting as $x) { if(! array_key_exists('updated',$x)) { logger('Deleting unreferenced hub location ' . $x['hubloc_addr']); - $r = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id = %d", + $r = q("update hubloc set hubloc_deleted = 1, hubloc_updated = '%s' where hubloc_id_url = '%s'", dbesc(datetime_convert()), - intval($x['hubloc_id']) + dbesc($x['hubloc_id_url']) ); $what .= 'removed_hub '; $changed = true; -- cgit v1.2.3 From 42ef6208c14ac579c1071ea880664dbcd42df907 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 23 Sep 2020 11:50:30 +0000 Subject: 5.0RC testing: do not use intval() on hubloc_id_url --- Zotlabs/Lib/Libsync.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index b16080a51..cff320e11 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -821,7 +821,7 @@ class Libsync { if(intval($r[0]['hubloc_primary']) && (! $location['primary'])) { $m = q("update hubloc set hubloc_primary = 0, hubloc_updated = '%s' where hubloc_id_url = '%s'", dbesc(datetime_convert()), - intval($r[0]['hubloc_id_url']) + dbesc($r[0]['hubloc_id_url']) ); $r[0]['hubloc_primary'] = intval($location['primary']); hubloc_change_primary($r[0]); -- cgit v1.2.3 From a7bf07b864ab74884f3f2bfabd57d9aa5ae1e49c Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 28 Sep 2020 20:31:26 +0000 Subject: 5.0RC testing: fix uuid for likes/dislikes --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 83c04c042..9c7b4e601 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2023,7 +2023,7 @@ class Activity { $s['mid'] = $act->id; $s['parent_mid'] = $act->obj['id']; - $s['uuid'] = $act->{'diaspora:guid'}; + $s['uuid'] = $act->data['diaspora:guid']; // over-ride the object timestamp with the activity -- cgit v1.2.3 From 48440e368c07855285da35ea9d0875196919a70d Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 30 Sep 2020 00:40:46 +0000 Subject: bug: undoing a like on a comment can remove the comment (cherry picked from commit b999456bf16a5d457a16fab1299289cfb54bfed4) --- Zotlabs/Lib/Activity.php | 19 +------------------ Zotlabs/Lib/Libzot.php | 6 +++++- 2 files changed, 6 insertions(+), 19 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9c7b4e601..7de2ca7ec 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -652,24 +652,7 @@ class Activity { else return []; - if ($i['obj']) { - if (! is_array($i['obj'])) { - $i['obj'] = json_decode($i['obj'],true); - } - $obj = self::encode_object($i['obj']); - if ($obj) - $ret['object'] = $obj; - else - return []; - } - else { - $obj = self::encode_item($i); - if ($obj) - $ret['object'] = $obj; - else - return []; - } - + $ret['object'] = str_replace('/item/','/activity/',$i['mid']); $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; return $ret; diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index f4eb26463..ce9536cd4 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1739,11 +1739,15 @@ class Libzot { continue; } + // reactions such as like and dislike could have an mid with /activity/ in it. + // Check for both forms in order to prevent duplicates. - $r = q("select * from item where mid = '%s' and uid = %d limit 1", + $r = q("select * from item where mid in ('%s','%s') and uid = %d limit 1", dbesc($arr['mid']), + dbesc(str_replace(z_root() . '/activity/', z_root() . '/item/', $arr['mid'])), intval($channel['channel_id']) ); + if($r) { // We already have this post. $item_id = $r[0]['id']; -- cgit v1.2.3 From b878b6902817c7f442281cef30d346bd2a60659f Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 30 Sep 2020 10:10:49 +0000 Subject: 5.0RC testing: fix issue in relation with deletes --- Zotlabs/Lib/Activity.php | 21 ++++++++++++++++++--- Zotlabs/Lib/Libzot.php | 6 +++++- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 7de2ca7ec..7ad6c91ae 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -652,13 +652,28 @@ class Activity { else return []; - $ret['object'] = str_replace('/item/','/activity/',$i['mid']); + if ($i['obj']) { + if (! is_array($i['obj'])) { + $i['obj'] = json_decode($i['obj'],true); + } + $obj = self::encode_object($i['obj']); + if ($obj) + $ret['object'] = $obj; + else + return []; + } + else { + $obj = self::encode_item($i,$activitypub); + if ($obj) + $ret['object'] = $obj; + else + return []; + } + $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; return $ret; - } - $ret['type'] = self::activity_mapper($i['verb']); if($ret['type'] === 'emojiReaction') { diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index ce9536cd4..a6db9e431 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -2116,12 +2116,16 @@ class Libzot { $item_found = false; $post_id = 0; + // reactions such as like and dislike could have an mid with /activity/ in it. + // Check for both forms in order to prevent duplicates. + $r = q("select * from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' ) - and mid = '%s' and uid = %d limit 1", + and mid IN ('%s', '%s') and uid = %d limit 1", dbesc($sender), dbesc($sender), dbesc($sender), dbesc($item['mid']), + dbesc(str_replace('/activity/', '/item/', $item['mid'])), intval($uid) ); -- cgit v1.2.3 From e529635952c9a10f56d3bc90a666eccd9c5b9842 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 30 Sep 2020 17:05:36 -0700 Subject: delete fixes --- Zotlabs/Lib/Libzot.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index a6db9e431..9b4b05878 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -2116,6 +2116,11 @@ class Libzot { $item_found = false; $post_id = 0; + $m = parse_url($item['mid']); + unset($m['fragment']); + $normalised = unparse_url($m); + + // reactions such as like and dislike could have an mid with /activity/ in it. // Check for both forms in order to prevent duplicates. @@ -2124,8 +2129,8 @@ class Libzot { dbesc($sender), dbesc($sender), dbesc($sender), - dbesc($item['mid']), - dbesc(str_replace('/activity/', '/item/', $item['mid'])), + dbesc($normalised), + dbesc(str_replace('/activity/', '/item/', $normalised)), intval($uid) ); -- cgit v1.2.3 From 8605aee53378075956753f6b06487d8d8129df3e Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 1 Oct 2020 06:34:27 +0000 Subject: use object url --- Zotlabs/Lib/Activity.php | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 7ad6c91ae..ae52fa216 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -652,24 +652,7 @@ class Activity { else return []; - if ($i['obj']) { - if (! is_array($i['obj'])) { - $i['obj'] = json_decode($i['obj'],true); - } - $obj = self::encode_object($i['obj']); - if ($obj) - $ret['object'] = $obj; - else - return []; - } - else { - $obj = self::encode_item($i,$activitypub); - if ($obj) - $ret['object'] = $obj; - else - return []; - } - + $ret['object'] = str_replace('/item/','/activity/',$i['mid']); $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; return $ret; } -- cgit v1.2.3 From 1d705b9805457b7c5f1b55023b7348712cc52604 Mon Sep 17 00:00:00 2001 From: nobody Date: Wed, 30 Sep 2020 23:38:05 -0700 Subject: deleting like/dislike/accept/reject/etc. activities should be Undo rather than Delete per the spec --- Zotlabs/Lib/Activity.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 7ad6c91ae..b084b1da8 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -644,7 +644,12 @@ class Activity { } if (intval($i['item_deleted'])) { - $ret['type'] = 'Delete'; + if (in_array($ret['type'], [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject' ])) { + $ret['type'] = 'Undo'; + } + else { + $ret['type'] = 'Delete'; + } $ret['id'] = str_replace('/item/','/activity/',$i['mid']) . '#delete'; $actor = self::encode_person($i['author'],false); if ($actor) @@ -2087,12 +2092,10 @@ class Activity { $s['edited'] = datetime_convert(); } - if($act->type === 'Tombstone' || $act->type === 'Delete' || ($act->type === 'Create' && $act->obj['type'] === 'Tombstone')) { + if(in_array($act->type, [ 'Delete', 'Undo', 'Tombstone' ]) || ($act->type === 'Create' && $act->obj['type'] === 'Tombstone')) { $s['item_deleted'] = 1; } - - $s['obj_type'] = self::activity_obj_decode_mapper($act->obj['type']); if($s['obj_type'] === ACTIVITY_OBJ_NOTE && $s['mid'] !== $s['parent_mid']) { $s['obj_type'] = ACTIVITY_OBJ_COMMENT; -- cgit v1.2.3 From 96c4c72ee36ebb19252be724ddb485a05337cb23 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 1 Oct 2020 11:16:03 +0000 Subject: minor issue --- Zotlabs/Lib/Activity.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 3f4875e93..6fac0c717 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -643,6 +643,8 @@ class Activity { $ret['obj'] = []; } + $ret['type'] = self::activity_mapper($i['verb']); + if (intval($i['item_deleted'])) { if (in_array($ret['type'], [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject' ])) { $ret['type'] = 'Undo'; @@ -662,8 +664,6 @@ class Activity { return $ret; } - $ret['type'] = self::activity_mapper($i['verb']); - if($ret['type'] === 'emojiReaction') { // There may not be an object for these items for legacy reasons - it should be the conversation parent. $p = q("select * from item where mid = '%s' and uid = %d", @@ -1058,6 +1058,8 @@ class Activity { 'http://purl.org/zot/activity/attendno' => 'Reject', 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept', 'Invite' => 'Invite', + 'Delete' => 'Delete', + 'Undo' => 'Undo' ]; call_hooks('activity_mapper',$acts); @@ -1105,6 +1107,8 @@ class Activity { 'http://purl.org/zot/activity/attendno' => 'Reject', 'http://purl.org/zot/activity/attendmaybe' => 'TentativeAccept', 'Invite' => 'Invite', + 'Delete' => 'Delete', + 'Undo' => 'Undo' ]; call_hooks('activity_decode_mapper',$acts); -- cgit v1.2.3 From 86117c88595cf97a6173fabcb9e3b0d5ec6b1d09 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 1 Oct 2020 11:51:20 +0000 Subject: more delete fixes --- Zotlabs/Lib/Activity.php | 23 ++++++++++++++++++++++- Zotlabs/Lib/Libzot.php | 9 ++------- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 6fac0c717..7cc77f124 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -645,9 +645,13 @@ class Activity { $ret['type'] = self::activity_mapper($i['verb']); + + if (intval($i['item_deleted'])) { + $is_response = false; if (in_array($ret['type'], [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject' ])) { $ret['type'] = 'Undo'; + $is_response = true; } else { $ret['type'] = 'Delete'; @@ -659,7 +663,24 @@ class Activity { else return []; - $ret['object'] = str_replace('/item/','/activity/',$i['mid']); + if ($i['obj'] && !$is_response) { + if (! is_array($i['obj'])) { + $i['obj'] = json_decode($i['obj'],true); + } + $obj = self::encode_object($i['obj']); + if ($obj) + $ret['object'] = $obj; + else + return []; + } + else { + $obj = self::encode_item($i); + if ($obj) + $ret['object'] = $obj; + else + return []; + } + $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; return $ret; } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 9b4b05878..87da5ff7a 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -2116,11 +2116,6 @@ class Libzot { $item_found = false; $post_id = 0; - $m = parse_url($item['mid']); - unset($m['fragment']); - $normalised = unparse_url($m); - - // reactions such as like and dislike could have an mid with /activity/ in it. // Check for both forms in order to prevent duplicates. @@ -2129,8 +2124,8 @@ class Libzot { dbesc($sender), dbesc($sender), dbesc($sender), - dbesc($normalised), - dbesc(str_replace('/activity/', '/item/', $normalised)), + dbesc(str_replace('/activity/', '/item/', $item['mid'])), + dbesc(str_replace('/item/', '/activity/', $item['mid'])), intval($uid) ); -- cgit v1.2.3 From 72c6d3e7baafd259ac00bcd2ff2da31c17e062f6 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 2 Oct 2020 12:09:23 +0000 Subject: item/activity fetching --- Zotlabs/Lib/Activity.php | 62 ++++++++++++++++++++++++++++++------------------ Zotlabs/Lib/Libzot.php | 11 ++++++--- 2 files changed, 47 insertions(+), 26 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 7cc77f124..d1a1a1385 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -644,41 +644,29 @@ class Activity { } $ret['type'] = self::activity_mapper($i['verb']); - - + $fragment = ''; if (intval($i['item_deleted'])) { - $is_response = false; if (in_array($ret['type'], [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject' ])) { $ret['type'] = 'Undo'; - $is_response = true; + $fragment = 'undo'; } else { $ret['type'] = 'Delete'; + $fragment = 'delete'; } - $ret['id'] = str_replace('/item/','/activity/',$i['mid']) . '#delete'; + + $ret['id'] = str_replace('/item/','/activity/',$i['mid']) . '#' . $fragment; $actor = self::encode_person($i['author'],false); if ($actor) $ret['actor'] = $actor; else return []; - if ($i['obj'] && !$is_response) { - if (! is_array($i['obj'])) { - $i['obj'] = json_decode($i['obj'],true); - } - $obj = self::encode_object($i['obj']); - if ($obj) - $ret['object'] = $obj; - else - return []; - } - else { - $obj = self::encode_item($i); - if ($obj) - $ret['object'] = $obj; - else - return []; + $ret['object'] = str_replace('/item/','/activity/',$i['mid']); + + if($i['id'] != $i['parent']) { + $ret['inReplyTo'] = $i['thr_parent']; } $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; @@ -1166,7 +1154,9 @@ class Activity { 'Question' => 'Question', 'Document' => 'Document', 'Audio' => 'Audio', - 'Video' => 'Video' + 'Video' => 'Video', + 'Delete' => 'Delete', + 'Undo' => 'Undo' ]; call_hooks('activity_obj_decode_mapper',$objs); @@ -1203,7 +1193,9 @@ class Activity { 'Invite' => 'Invite', 'Question' => 'Question', 'Audio' => 'Audio', - 'Video' => 'Video' + 'Video' => 'Video', + 'Delete' => 'Delete', + 'Undo' => 'Undo' ]; call_hooks('activity_obj_mapper',$objs); @@ -3115,5 +3107,29 @@ class Activity { return $content; } + // Find either an Authorization: Bearer token or 'token' request variable + // in the current web request and return it + + static function token_from_request() { + + foreach ( [ 'REDIRECT_REMOTE_USER', 'HTTP_AUTHORIZATION' ] as $s ) { + $auth = ((array_key_exists($s,$_SERVER) && strpos($_SERVER[$s],'Bearer ') === 0) + ? str_replace('Bearer ', EMPTY_STR, $_SERVER[$s]) + : EMPTY_STR + ); + if ($auth) { + break; + } + } + + if (! $auth) { + if (array_key_exists('token',$_REQUEST) && $_REQUEST['token']) { + $auth = $_REQUEST['token']; + } + } + + return $auth; + } + } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 87da5ff7a..d7285ca12 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1496,13 +1496,14 @@ class Libzot { // Try again using the delivery channel credentials. // We will also need to re-parse the $item array, // but preserve any values that were set during anonymous parsing. - + $o = Activity::fetch($act->obj,$channel); if($o) { $act->obj = $o; $arr = array_merge(Activity::decode_note($act),$arr); } else { + $DR->update('Incomplete or corrupt activity'); $result[] = $DR->get(); continue; @@ -2116,6 +2117,10 @@ class Libzot { $item_found = false; $post_id = 0; + $m = parse_url($item['mid']); + unset($m['fragment']); + $normalised = unparse_url($m); + // reactions such as like and dislike could have an mid with /activity/ in it. // Check for both forms in order to prevent duplicates. @@ -2124,8 +2129,8 @@ class Libzot { dbesc($sender), dbesc($sender), dbesc($sender), - dbesc(str_replace('/activity/', '/item/', $item['mid'])), - dbesc(str_replace('/item/', '/activity/', $item['mid'])), + dbesc($normalised), + dbesc(str_replace('/activity/', '/item/', $normalised)), intval($uid) ); -- cgit v1.2.3 From 93b90ab23a7ba4bf4867510a2a4798ef63f9098e Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 2 Oct 2020 15:12:42 +0000 Subject: more work on delete/undo --- Zotlabs/Lib/Activity.php | 4 ++-- Zotlabs/Lib/Libzot.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index d1a1a1385..631606c46 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2020,12 +2020,12 @@ class Activity { $s['expires'] = datetime_convert('UTC','UTC',$act->obj['expires']); } - if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction' ])) { + if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction', 'Undo', 'Delete' ])) { $response_activity = true; $s['mid'] = $act->id; - $s['parent_mid'] = $act->obj['id']; + $s['parent_mid'] = $act->parent_id; //$act->obj['id']; $s['uuid'] = $act->data['diaspora:guid']; // over-ride the object timestamp with the activity diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index d7285ca12..ab322ca86 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1141,6 +1141,7 @@ class Libzot { } logger($AS->debug(),LOGGER_DATA); + } -- cgit v1.2.3 From 244c8edfca6cc7ab48c337bda37ab70bfe819413 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 5 Oct 2020 11:47:22 +0000 Subject: =?UTF-8?q?=C3=83rework=20undo/delete=20to=20use=20inline=20object?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zotlabs/Lib/Activity.php | 46 +++++++++++++++++++++++++++++++++++++++------- Zotlabs/Lib/Libzot.php | 45 +++++++++++++++++---------------------------- 2 files changed, 56 insertions(+), 35 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 631606c46..9a31304d1 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -319,6 +319,26 @@ class Activity { $ret = Activity::encode_object($i['obj']); } + if (intval($i['item_deleted'])) { + $ret['type'] = 'Tombstone'; + $ret['formerType'] = $objtype; + $ret['id'] = $i['mid']; + if($i['id'] != $i['parent']) + $ret['inReplyTo'] = $i['thr_parent']; + + $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; + return $ret; + } + + if ($i['obj']) { + if (is_array($i['obj'])) { + $ret = $i['obj']; + } + else { + $ret = json_decode($i['obj'],true); + } + } + $ret['type'] = $objtype; if ($objtype === 'Question') { @@ -632,7 +652,7 @@ class Activity { - static function encode_activity($i) { + static function encode_activity($i, $dismiss_deleted = false) { $ret = []; $reply = false; @@ -646,10 +666,13 @@ class Activity { $ret['type'] = self::activity_mapper($i['verb']); $fragment = ''; - if (intval($i['item_deleted'])) { + if (intval($i['item_deleted']) && !$dismiss_deleted) { + $is_response = false; + if (in_array($ret['type'], [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject' ])) { $ret['type'] = 'Undo'; $fragment = 'undo'; + $is_response = true; } else { $ret['type'] = 'Delete'; @@ -663,14 +686,23 @@ class Activity { else return []; - $ret['object'] = str_replace('/item/','/activity/',$i['mid']); +// $ret['object'] = str_replace('/item/','/activity/',$i['mid']); - if($i['id'] != $i['parent']) { - $ret['inReplyTo'] = $i['thr_parent']; + $obj = (($is_response) ? self::encode_activity($i,true) : self::encode_item($i,true)); + if ($obj) { + // do not leak private content in deletes + unset($obj['object']); + unset($obj['cc']); + $obj['to'] = [ ACTIVITY_PUBLIC_INBOX ]; + $ret['object'] = $obj; } + else + return []; $ret['to'] = [ ACTIVITY_PUBLIC_INBOX ]; + return $ret; + } if($ret['type'] === 'emojiReaction') { @@ -2020,12 +2052,12 @@ class Activity { $s['expires'] = datetime_convert('UTC','UTC',$act->obj['expires']); } - if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction', 'Undo', 'Delete' ])) { + if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction' ])) { $response_activity = true; $s['mid'] = $act->id; - $s['parent_mid'] = $act->parent_id; //$act->obj['id']; + // $s['parent_mid'] = $act->obj['id']; $s['uuid'] = $act->data['diaspora:guid']; // over-ride the object timestamp with the activity diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index ab322ca86..f16f5258a 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1202,10 +1202,6 @@ class Libzot { if(in_array($env['type'],['activity','response'])) { - $arr = Activity::decode_note($AS); - - //logger($AS->debug()); - $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s' ", dbesc($AS->actor['id']) ); @@ -1727,7 +1723,7 @@ class Libzot { $arr['aid'] = $channel['channel_account_id']; $arr['uid'] = $channel['channel_id']; - $item_id = self::delete_imported_item($sender,$arr,$channel['channel_id'],$relay); + $item_id = self::delete_imported_item($sender,$act,$arr,$channel['channel_id'],$relay); $DR->update(($item_id) ? 'deleted' : 'delete_failed'); $result[] = $DR->get(); @@ -2110,7 +2106,7 @@ class Libzot { * @return boolean|int post_id */ - static function delete_imported_item($sender, $item, $uid, $relay) { + static function delete_imported_item($sender, $act, $item, $uid, $relay) { logger('invoked', LOGGER_DEBUG); @@ -2118,46 +2114,39 @@ class Libzot { $item_found = false; $post_id = 0; - $m = parse_url($item['mid']); - unset($m['fragment']); - $normalised = unparse_url($m); + if ($item['verb'] === 'Tombstone') { + // The id of the deleted thing is the item mid (activity id) + $mid = $item['mid']; + } + else { + // The id is the object id if the type is Undo or Delete + $mid = ((is_array($act->obj)) ? $act->obj['id'] : $act->obj); + } - // reactions such as like and dislike could have an mid with /activity/ in it. - // Check for both forms in order to prevent duplicates. + // we may have stored either the object id or the activity id if it was a response activity (like, dislike, etc.) $r = q("select * from item where ( author_xchan = '%s' or owner_xchan = '%s' or source_xchan = '%s' ) and mid IN ('%s', '%s') and uid = %d limit 1", dbesc($sender), dbesc($sender), dbesc($sender), - dbesc($normalised), - dbesc(str_replace('/activity/', '/item/', $normalised)), + dbesc($mid), + dbesc(str_replace('/activity/','/item/',$mid)), intval($uid) ); if($r) { $stored = $r[0]; - if($stored['author_xchan'] === $sender || $stored['owner_xchan'] === $sender || $stored['source_xchan'] === $sender) - $ownership_valid = true; + // we proved ownership in the sql query + $ownership_valid = true; $post_id = $stored['id']; $item_found = true; } else { - - // perhaps the item is still in transit and the delete notification got here before the actual item did. Store it with the deleted flag set. - // item_store() won't try to deliver any notifications or start delivery chains if this flag is set. - // This means we won't end up with potentially even more delivery threads trying to push this delete notification. - // But this will ensure that if the (undeleted) original post comes in at a later date, we'll reject it because it will have an older timestamp. - - logger('delete received for non-existent item - storing item data.'); - - if($item['author_xchan'] === $sender || $item['owner_xchan'] === $sender || $item['source_xchan'] === $sender) { - $ownership_valid = true; - $item_result = item_store($item); - $post_id = $item_result['item_id']; - } + // this will fail with an ownership issue, so explain the real reason + logger('delete received for non-existent item or not owned by sender - ignoring.'); } if($ownership_valid === false) { -- cgit v1.2.3 From b37c8bf9287efd3ae810560be356ba96848a2573 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 6 Oct 2020 08:25:53 +0000 Subject: code optimisation --- Zotlabs/Lib/Activity.php | 15 +++++++-------- Zotlabs/Lib/ActivityStreams.php | 15 ++++++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9a31304d1..13ba224cb 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -652,7 +652,7 @@ class Activity { - static function encode_activity($i, $dismiss_deleted = false) { + static function encode_activity($i, $recurse = false) { $ret = []; $reply = false; @@ -666,10 +666,10 @@ class Activity { $ret['type'] = self::activity_mapper($i['verb']); $fragment = ''; - if (intval($i['item_deleted']) && !$dismiss_deleted) { + if (intval($i['item_deleted']) && !$recurse) { $is_response = false; - if (in_array($ret['type'], [ 'Like', 'Dislike', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject' ])) { + if (ActivityStreams::is_response_activity($ret['type'])) { $ret['type'] = 'Undo'; $fragment = 'undo'; $is_response = true; @@ -686,12 +686,11 @@ class Activity { else return []; -// $ret['object'] = str_replace('/item/','/activity/',$i['mid']); - $obj = (($is_response) ? self::encode_activity($i,true) : self::encode_item($i,true)); if ($obj) { - // do not leak private content in deletes - unset($obj['object']); + if (array_path_exists('object/id',$obj)) { + $obj['object'] = $obj['object']['id']; + } unset($obj['cc']); $obj['to'] = [ ACTIVITY_PUBLIC_INBOX ]; $ret['object'] = $obj; @@ -2052,7 +2051,7 @@ class Activity { $s['expires'] = datetime_convert('UTC','UTC',$act->obj['expires']); } - if(in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'emojiReaction' ])) { + if(ActivityStreams::is_response_activity($act->type)) { $response_activity = true; diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php index b1ef59364..a0ba52aa6 100644 --- a/Zotlabs/Lib/ActivityStreams.php +++ b/Zotlabs/Lib/ActivityStreams.php @@ -274,12 +274,19 @@ class ActivityStreams { return self::fetch($url); } - static function fetch($url,$channel = null) { - return Activity::fetch($url,$channel); + static function fetch($url, $channel = null) { + return Activity::fetch($url, $channel); } static function is_an_actor($s) { - return(in_array($s,[ 'Application','Group','Organization','Person','Service' ])); + return (in_array($s, [ 'Application','Group','Organization','Person','Service' ])); + } + + static function is_response_activity($s) { + if (! $s) { + return false; + } + return (in_array($s, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', 'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction', 'EmojiReact' ])); } /** @@ -402,7 +409,6 @@ class ActivityStreams { return $x; } - static function is_as_request() { $x = getBestSupportedMimeType([ @@ -415,5 +421,4 @@ class ActivityStreams { } - } -- cgit v1.2.3 From 5dd1ea21afcd4df9e91e6e215cb8ae1d32f5616e Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 6 Oct 2020 10:01:20 +0000 Subject: 5.0RC testing: dismiss activities where an author could not be found --- Zotlabs/Lib/Libzot.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index f16f5258a..44f1f399e 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1212,6 +1212,10 @@ class Libzot { $arr['author_xchan'] = $r['hubloc_hash']; } + if (! $arr['author_xchan']) { + logger('No author!'); + return; + } $s = q("select hubloc_hash from hubloc where hubloc_id_url = '%s' and hubloc_network = 'zot6' limit 1", dbesc($env['sender']) -- cgit v1.2.3 From c387902a4415b9e04c4e3cae5f9c8fe8b3540a12 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 9 Oct 2020 07:19:23 +0000 Subject: 5.0RC testing: correctly set permissions for rss feeds --- Zotlabs/Lib/Connect.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php index caac30f7a..481b02ce2 100644 --- a/Zotlabs/Lib/Connect.php +++ b/Zotlabs/Lib/Connect.php @@ -187,12 +187,8 @@ class Connect { // Always set these "remote" permissions for feeds since we cannot interact with them // to negotiate a suitable permission response - $p = get_abconfig($uid,$xchan_hash,'system','their_perms',EMPTY_STR); - if ($p) { - $p .= ','; - } - $p .= 'view_stream,republish'; - set_abconfig($uid,$xchan_hash,'system','their_perms',$p); + set_abconfig($uid,$xchan_hash,'their_perms','view_stream',1); + set_abconfig($uid,$xchan_hash,'their_perms','republish',1); } -- cgit v1.2.3 From 1215618589636fd433d69fa5d81f2aca264beef5 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 9 Oct 2020 12:16:55 +0000 Subject: add zot6 to the authenticatable options and fix array key in reshare header --- Zotlabs/Lib/Share.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Share.php b/Zotlabs/Lib/Share.php index f8b636c10..419e6ed5f 100644 --- a/Zotlabs/Lib/Share.php +++ b/Zotlabs/Lib/Share.php @@ -128,7 +128,7 @@ class Share { "' profile='" . $this->item['author']['xchan_url'] . "' avatar='" . $this->item['author']['xchan_photo_s'] . "' link='" . $this->item['plink'] . - "' auth='" . (($this->item['author']['network'] === 'zot') ? 'true' : 'false') . + "' auth='" . ((in_array($this->item['author']['xchan_network'], ['zot6', 'zot'])) ? 'true' : 'false') . "' posted='" . $this->item['created'] . "' message_id='" . $this->item['mid'] . "']"; -- cgit v1.2.3 From 595f3d99b4bd2618630f9a49423b29bfbfcbca41 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 10 Oct 2020 08:00:25 +0000 Subject: quickfix localize_item() - requires more work --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 13ba224cb..e3798415c 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2921,7 +2921,7 @@ class Activity { $s['parent_mid'] = $s['mid']; - $post_type = (($parent_item['resource_type'] === 'photo') ? t('photo') : t('status')); + $post_type = (($parent_item['resource_type'] === 'photo') ? t('photo') : t('post')); $links = array(array('rel' => 'alternate','type' => 'text/html', 'href' => $parent_item['plink'])); $objtype = (($parent_item['resource_type'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE ); -- cgit v1.2.3 From ed845d93bc7ac5f46ccb1ea95d53bc5e5f2756bd Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 10 Oct 2020 19:06:35 +0000 Subject: 5.0RC testing: fix issue with event responses --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index e3798415c..af7d945ba 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -168,7 +168,7 @@ class Activity { if($r) { xchan_query($r,true); $r = fetch_post_tags($r,true); - if ($r[0]['verb'] === 'Create' && $r[0]['obj_type'] === ACTIVITY_OBJ_EVENT) { + if (in_array($r[0]['verb'], ['Create', 'Invite']) && $r[0]['obj_type'] === ACTIVITY_OBJ_EVENT) { $r[0]['verb'] = 'Invite'; return self::encode_activity($r[0]); } -- cgit v1.2.3 From 4a671fe634a4a8463703dd661a238f5545f5a5e4 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Oct 2020 10:50:03 +0000 Subject: replace linebreaks with spaces --- Zotlabs/Lib/Enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 03a824b9b..fad249e47 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -859,7 +859,7 @@ class Enotify { 'b64mid' => (($item['mid']) ? 'b64.' . base64url_encode($item['mid']) : ''), //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'thread_top' => (($item['item_thread_top']) ? true : false), - 'message' => bbcode(escape_tags($itemem_text)), + 'message' => bbcode(escape_tags(str_replace(["\r\n", "\r", "\n"], ' ', $itemem_text))), 'body' => htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_COMPAT, 'UTF-8', false), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], -- cgit v1.2.3 From 4d2507263dbeba3b945efab5f3fcfc676558ded1 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Oct 2020 19:35:48 +0000 Subject: find best identity --- Zotlabs/Lib/Activity.php | 32 ++++++++++++++++++++++++++++++++ Zotlabs/Lib/Libzot.php | 5 +++++ 2 files changed, 37 insertions(+) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index af7d945ba..f3885033b 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1736,6 +1736,23 @@ class Activity { $s['aid'] = $channel['channel_account_id']; $s['uid'] = $channel['channel_id']; + + // Make sure we use the zot6 identity where applicable + + $s['author_xchan'] = self::find_best_identity($s['author_xchan']); + $s['owner_xchan'] = self::find_best_identity($s['owner_xchan']); + + if(!$s['author_xchan']) { + logger('No author: ' . print_r($act, true)); + } + + if(!$s['owner_xchan']) { + logger('No owner: ' . print_r($act, true)); + } + + if(!$s['author_xchan'] || !$s['owner_xchan']) + return; + $s['mid'] = urldecode($act->obj['id']); $s['uuid'] = $act->obj['diaspora:guid']; $s['plink'] = urldecode($act->obj['id']); @@ -2477,6 +2494,11 @@ class Activity { $item['aid'] = $channel['channel_account_id']; $item['uid'] = $channel['channel_id']; + // Make sure we use the zot6 identity where applicable + + $item['author_xchan'] = self::find_best_identity($item['author_xchan']); + $item['owner_xchan'] = self::find_best_identity($item['owner_xchan']); + if(! ( $item['author_xchan'] && $item['owner_xchan'])) { logger('owner or author missing.'); return; @@ -3162,5 +3184,15 @@ class Activity { return $auth; } + static function find_best_identity($xchan) { + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s'", + dbesc($xchan) + ); + if ($r) { + $r = Libzot::zot_record_preferred($r); + return $r['hubloc_hash']; + } + return $xchan; + } } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 44f1f399e..fb64626d6 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1467,6 +1467,11 @@ class Libzot { $result = []; + // Make sure we use the zot6 identity where applicable + + $msg_arr['author_xchan'] = Activity::find_best_identity($msg_arr['author_xchan']); + $msg_arr['owner_xchan'] = Activity::find_best_identity($msg_arr['owner_xchan']); + // We've validated the sender. Now make sure that the sender is the owner or author if(! $public) { -- cgit v1.2.3 From 8595835aa0d5fff5a51d6c8c42dbb6ff140b4f57 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Oct 2020 19:48:35 +0000 Subject: revert linebreak removing --- Zotlabs/Lib/Enotify.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index fad249e47..03a824b9b 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -859,7 +859,7 @@ class Enotify { 'b64mid' => (($item['mid']) ? 'b64.' . base64url_encode($item['mid']) : ''), //'b64mid' => ((in_array($item['verb'], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) ? 'b64.' . base64url_encode($item['thr_parent']) : 'b64.' . base64url_encode($item['mid'])), 'thread_top' => (($item['item_thread_top']) ? true : false), - 'message' => bbcode(escape_tags(str_replace(["\r\n", "\r", "\n"], ' ', $itemem_text))), + 'message' => bbcode(escape_tags($itemem_text)), 'body' => htmlentities(html2plain(bbcode($item['body']), 75, true), ENT_COMPAT, 'UTF-8', false), // these are for the superblock addon 'hash' => $item[$who]['xchan_hash'], -- cgit v1.2.3 From 5f93157d5a5cc824d98c39d1983d882df0a13067 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Oct 2020 20:28:48 +0000 Subject: improve find_best_identity() and fix wrong variable --- Zotlabs/Lib/Activity.php | 17 +++++++++++------ Zotlabs/Lib/Libzot.php | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index f3885033b..4886f9239 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3185,14 +3185,19 @@ class Activity { } static function find_best_identity($xchan) { - $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s'", - dbesc($xchan) - ); - if ($r) { - $r = Libzot::zot_record_preferred($r); - return $r['hubloc_hash']; + + if(filter_var($xchan, FILTER_VALIDATE_URL)) { + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s'", + dbesc($xchan) + ); + if ($r) { + $r = Libzot::zot_record_preferred($r); + return $r['hubloc_hash']; + } } + return $xchan; + } } diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index fb64626d6..654b0461b 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1469,8 +1469,8 @@ class Libzot { // Make sure we use the zot6 identity where applicable - $msg_arr['author_xchan'] = Activity::find_best_identity($msg_arr['author_xchan']); - $msg_arr['owner_xchan'] = Activity::find_best_identity($msg_arr['owner_xchan']); + $arr['author_xchan'] = Activity::find_best_identity($arr['author_xchan']); + $arr['owner_xchan'] = Activity::find_best_identity($arr['owner_xchan']); // We've validated the sender. Now make sure that the sender is the owner or author -- cgit v1.2.3 From e12f375624d980702e0ae81cdd161c77ccd527ca Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 13 Oct 2020 07:25:33 +0000 Subject: return if author or owner is missing and add more logging --- Zotlabs/Lib/Activity.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 4886f9239..6d12f7ea1 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2499,11 +2499,17 @@ class Activity { $item['author_xchan'] = self::find_best_identity($item['author_xchan']); $item['owner_xchan'] = self::find_best_identity($item['owner_xchan']); - if(! ( $item['author_xchan'] && $item['owner_xchan'])) { - logger('owner or author missing.'); - return; + if(!$item['author_xchan']) { + logger('No author: ' . print_r($act, true)); } + if(!$item['owner_xchan']) { + logger('No owner: ' . print_r($act, true)); + } + + if(!$item['author_xchan'] || !$item['owner_xchan']) + return; + if($channel['channel_system']) { if(! MessageFilter::evaluate($item,get_config('system','pubstream_incl'),get_config('system','pubstream_excl'))) { logger('post is filtered'); @@ -2699,6 +2705,7 @@ class Activity { static public function fetch_and_store_replies($channel, $arr) { logger('fetching replies'); + logger(print_r($arr,true)); $p = []; -- cgit v1.2.3 From b103993ad155c8b304a6ce6fa345251691c0fb54 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 13 Oct 2020 08:14:14 +0000 Subject: this is not required here --- Zotlabs/Lib/Libzot.php | 5 ----- 1 file changed, 5 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 654b0461b..44f1f399e 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -1467,11 +1467,6 @@ class Libzot { $result = []; - // Make sure we use the zot6 identity where applicable - - $arr['author_xchan'] = Activity::find_best_identity($arr['author_xchan']); - $arr['owner_xchan'] = Activity::find_best_identity($arr['owner_xchan']); - // We've validated the sender. Now make sure that the sender is the owner or author if(! $public) { -- cgit v1.2.3 From e2e160b8e8d01eb0d2c537318f1d738aef9df9c8 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Oct 2020 07:33:30 +0000 Subject: In find_best_identity() only look for zot and zot6 network types. Otherwise we could end up rewriting activitypub contacts to their diaspora equivalent which would be counterproductive here. Dismiss deleted hublocs. Same applies for find_best_zot_identity(). Also add logging. --- Zotlabs/Lib/Activity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 6d12f7ea1..08e5ffaca 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3194,11 +3194,12 @@ class Activity { static function find_best_identity($xchan) { if(filter_var($xchan, FILTER_VALIDATE_URL)) { - $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s'", + $r = q("select hubloc_hash, hubloc_network from hubloc where hubloc_id_url = '%s' and hubloc_network in ('zot6', 'zot') and hubloc_deleted = 0", dbesc($xchan) ); if ($r) { $r = Libzot::zot_record_preferred($r); + logger('find_best_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); return $r['hubloc_hash']; } } -- cgit v1.2.3 From ea77043aaf0419f065ab47cb38e98203918f3465 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Oct 2020 08:53:12 +0000 Subject: more logging --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 08e5ffaca..204d19480 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3199,7 +3199,7 @@ class Activity { ); if ($r) { $r = Libzot::zot_record_preferred($r); - logger('find_best_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); + hz_syslog('find_best_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); return $r['hubloc_hash']; } } -- cgit v1.2.3 From 522b92128f076114da8f25e18151387d9012d33c Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 14 Oct 2020 12:32:18 +0000 Subject: use logger for logging --- Zotlabs/Lib/Activity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 204d19480..08e5ffaca 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -3199,7 +3199,7 @@ class Activity { ); if ($r) { $r = Libzot::zot_record_preferred($r); - hz_syslog('find_best_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); + logger('find_best_identity: ' . $xchan . ' > ' . $r['hubloc_hash']); return $r['hubloc_hash']; } } -- cgit v1.2.3 From d84f0030beaf353b3bd3e02e21019663988227ef Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 16 Oct 2020 10:21:58 +0000 Subject: on refresh, always set all perms --- Zotlabs/Lib/Libzot.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index 44f1f399e..f0fe3ab24 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -326,14 +326,10 @@ class Libzot { if($permissions && is_array($permissions)) { $old_read_stream_perm = get_abconfig($channel['channel_id'],$x['hash'],'their_perms','view_stream'); - // We need to reset their_perms prior to setting the new ones. - // Otherwise withdrawn permissions will not take effect locally. - q("DELETE FROM abconfig WHERE chan = %d AND xchan = '%s' AND cat = 'their_perms'", - intval($channel['channel_id']), - dbesc($x['hash']) - ); - foreach($permissions as $p) { - set_abconfig($channel['channel_id'],$x['hash'],'their_perms',$p,'1'); + $permissions = Permissions::FilledPerms($permissions); + + foreach($permissions as $k => $v) { + set_abconfig($channel['channel_id'],$x['hash'],'their_perms',$k,$v); } } -- cgit v1.2.3 From cef0c2ebb2b16b006eca7dce8ec0b1a95d916dba Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 19 Oct 2020 08:44:44 +0000 Subject: highlight events for today in notifications and remove some redundant css --- Zotlabs/Lib/Enotify.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Enotify.php b/Zotlabs/Lib/Enotify.php index 03a824b9b..c78325ee3 100644 --- a/Zotlabs/Lib/Enotify.php +++ b/Zotlabs/Lib/Enotify.php @@ -966,8 +966,8 @@ class Enotify { 'url' => $rr['xchan_url'], 'photo' => $rr['xchan_photo_s'], 'when' => $when, - 'hclass' => ('notify-unseen'), - 'message' => t('posted an event') + 'hclass' => (($today) ? 'notify-unseen bg-warning' : 'notify-unseen'), + 'message' => t('created an event') ]; return $x; -- cgit v1.2.3 From d3d5ddfb434555373b892e127ad9faa6425af3bf Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 24 Oct 2020 21:26:46 +0000 Subject: enable btlogging to syslog (cherry picked from commit 5580fc1954a63f861644e2de3773fbb3adfa8f2c) --- Zotlabs/Lib/Webfinger.php | 2 +- Zotlabs/Lib/Zotfinger.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Webfinger.php b/Zotlabs/Lib/Webfinger.php index c2364ac4d..611c36889 100644 --- a/Zotlabs/Lib/Webfinger.php +++ b/Zotlabs/Lib/Webfinger.php @@ -106,4 +106,4 @@ class Webfinger { -} \ No newline at end of file +} diff --git a/Zotlabs/Lib/Zotfinger.php b/Zotlabs/Lib/Zotfinger.php index 2d2e6796b..722e34dfc 100644 --- a/Zotlabs/Lib/Zotfinger.php +++ b/Zotlabs/Lib/Zotfinger.php @@ -60,4 +60,4 @@ class Zotfinger { -} \ No newline at end of file +} -- cgit v1.2.3 From 81775eebe2f737c115f50d52d18c20e8442158f4 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 25 Oct 2020 07:59:49 +0000 Subject: directory fixes --- Zotlabs/Lib/Libzotdir.php | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Libzotdir.php b/Zotlabs/Lib/Libzotdir.php index 1cb52275c..b02516a98 100644 --- a/Zotlabs/Lib/Libzotdir.php +++ b/Zotlabs/Lib/Libzotdir.php @@ -3,6 +3,8 @@ namespace Zotlabs\Lib; use Zotlabs\Lib\Libzot; +use Zotlabs\Lib\Zotfinger; +use Zotlabs\Lib\Webfinger; require_once('include/permissions.php'); @@ -307,9 +309,9 @@ class Libzotdir { if ($ud['ud_addr'] && (! ($ud['ud_flags'] & UPDATE_FLAGS_DELETED))) { $success = false; - $href = \Zotlabs\Lib\Webfinger::zot_url(punify($ud['ud_addr'])); + $href = Webfinger::zot_url(punify($ud['ud_addr'])); if($href) { - $zf = \Zotlabs\Lib\Zotfinger::exec($href); + $zf = Zotfinger::exec($href); } if(is_array($zf) && array_path_exists('signature/signer',$zf) && $zf['signature']['signer'] === $href && intval($zf['signature']['header_valid'])) { $xc = Libzot::import_xchan($zf['data'], 0, $ud); @@ -339,7 +341,7 @@ class Libzotdir { logger('local_dir_update: uid: ' . $uid, LOGGER_DEBUG); - $p = q("select channel.channel_hash, channel_address, channel_timezone, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1", + $p = q("select channel.channel_hash, channel_address, channel_timezone, channel_portable_id, profile.* from profile left join channel on channel_id = uid where uid = %d and is_default = 1", intval($uid) ); @@ -348,6 +350,7 @@ class Libzotdir { if ($p) { $hash = $p[0]['channel_hash']; + $legacy_hash = $p[0]['channel_portable_id']; $profile['description'] = $p[0]['pdesc']; $profile['birthday'] = $p[0]['dob']; @@ -381,14 +384,15 @@ class Libzotdir { logger('hidden: ' . $hidden); - $r = q("select xchan_hidden from xchan where xchan_hash = '%s' limit 1", + $r = q("select xchan_hidden from xchan where xchan_hash = '%s'", dbesc($p[0]['channel_hash']) ); if(intval($r[0]['xchan_hidden']) != $hidden) { - $r = q("update xchan set xchan_hidden = %d where xchan_hash = '%s'", + $r = q("update xchan set xchan_hidden = %d where xchan_hash in ('%s', '%s')", intval($hidden), - dbesc($p[0]['channel_hash']) + dbesc($hash), + dbesc($legacy_hash) ); } @@ -402,11 +406,13 @@ class Libzotdir { } else { // they may have made it private - $r = q("delete from xprof where xprof_hash = '%s'", - dbesc($hash) + q("delete from xprof where xprof_hash in ('%s', '%s')", + dbesc($hash), + dbesc($legacy_hash) ); - $r = q("delete from xtag where xtag_hash = '%s'", - dbesc($hash) + q("delete from xtag where xtag_hash in ('%s', '%s')", + dbesc($hash), + dbesc($legacy_hash) ); } -- cgit v1.2.3 From 207df132e69bd3e70f28addbd63bd3c638da9b08 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Nov 2020 13:36:52 +0000 Subject: make sure we attach the public key --- Zotlabs/Lib/Activity.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Lib') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 08e5ffaca..e7fa6352a 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1018,6 +1018,7 @@ class Activity { if(! $extended) { return $p['xchan_url']; } + $ret = []; $c = ((array_key_exists('channel_id',$p)) ? $p : channelx_by_hash($p['xchan_hash'])); @@ -1063,10 +1064,16 @@ class Activity { ] ]; + $ret['publicKey'] = [ + 'id' => $p['xchan_url'], + 'owner' => $p['xchan_url'], + 'publicKeyPem' => $p['xchan_pubkey'] + ]; + $arr = [ 'xchan' => $p, 'encoded' => $ret ]; call_hooks('encode_person', $arr); - $ret = $arr['encoded']; + $ret = $arr['encoded']; return $ret; } -- cgit v1.2.3