From f7efbfc7c2c5d33459500e96579c610551e39bad Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 4 Feb 2020 15:44:26 -0800 Subject: [PATCH] more emojireaction work and a config setting to allow messages where you are mentioned, over-riding normal permissions. --- Zotlabs/Lib/Activity.php | 4 ++-- Zotlabs/Module/Apschema.php | 2 +- Zotlabs/Module/Inbox.php | 1 + Zotlabs/Module/Item.php | 2 +- Zotlabs/Module/Settings/Channel.php | 7 ++++-- include/items.php | 37 ++++++++++++++++++++++++++++- include/text.php | 1 - view/tpl/settings.tpl | 5 ++-- 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 4246d1ee7..1aef5696f 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -1869,7 +1869,7 @@ class Activity { } if (in_array($act->type, [ 'Like', 'Dislike', 'Flag', 'Block', 'Announce', 'Accept', 'Reject', - 'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction' ])) { + 'TentativeAccept', 'TentativeReject', 'emojiReaction', 'EmojiReaction', 'EmojiReact' ])) { $response_activity = true; @@ -1939,7 +1939,7 @@ class Activity { // Hubzilla reactions $content['content'] = (($act->tgt && $act->tgt['type'] === 'Image') ? '[img=32x32]' . $act->tgt['url'] . '[/img]' : '&#x' . $act->tgt['name'] . ';'); } - if ($act->type === 'EmojiReaction') { + if (in_array($act->type,[ 'EmojiReaction', 'EmojiReact' ])) { // Pleroma reactions $t = trim(self::get_textfield($act,'content')); $e = Emoji\is_single_emoji($t); diff --git a/Zotlabs/Module/Apschema.php b/Zotlabs/Module/Apschema.php index 1a5d53388..a4eec30dd 100644 --- a/Zotlabs/Module/Apschema.php +++ b/Zotlabs/Module/Apschema.php @@ -21,7 +21,7 @@ class Apschema extends \Zotlabs\Web\Controller { 'copiedTo' => 'as:copiedTo', 'alsoKnownAs' => 'as:alsoKnownAs', 'inheritPrivacy' => 'as:inheritPrivacy', - 'EmojiReaction' => 'as:EmojiReaction', + 'EmojiReact' => 'as:EmojiReact', 'commentPolicy' => 'zot:commentPolicy', 'topicalCollection' => 'zot:topicalCollection', 'eventRepeat' => 'zot:eventRepeat', diff --git a/Zotlabs/Module/Inbox.php b/Zotlabs/Module/Inbox.php index ddb0a573b..6418eba59 100644 --- a/Zotlabs/Module/Inbox.php +++ b/Zotlabs/Module/Inbox.php @@ -248,6 +248,7 @@ class Inbox extends Controller { case 'View': case 'emojiReaction': case 'EmojiReaction': + case 'EmojiReact': // These require a resolvable object structure if (is_array($AS->obj)) { $item = Activity::decode_note($AS); diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index d82ea2aa8..9c2dd1013 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -490,7 +490,7 @@ class Item extends Controller { if (mb_strlen($_REQUEST['body']) < 10) { $t = Emoji\is_single_emoji(trim($_REQUEST['body'])); if ($t) { - $obj_type = 'EmojiReaction'; + $obj_type = 'EmojiReact'; } } diff --git a/Zotlabs/Module/Settings/Channel.php b/Zotlabs/Module/Settings/Channel.php index ed3df8d37..044bfee25 100644 --- a/Zotlabs/Module/Settings/Channel.php +++ b/Zotlabs/Module/Settings/Channel.php @@ -169,7 +169,8 @@ class Channel { $cal_first_day = (((x($_POST,'first_day')) && intval($_POST['first_day']) >= 0 && intval($_POST['first_day']) < 7) ? intval($_POST['first_day']) : 0); $mailhost = ((array_key_exists('mailhost',$_POST)) ? notags(trim($_POST['mailhost'])) : ''); $profile_assign = ((x($_POST,'profile_assign')) ? notags(trim($_POST['profile_assign'])) : ''); - + $permit_all_mentions = (($_POST['permit_all_mentions'] == 1) ? 1: 0); + // allow a permission change to over-ride the autoperms setting from the form if(! isset($autoperms)) { @@ -279,6 +280,7 @@ class Channel { set_pconfig(local_channel(),'system','hyperdrive',$hyperdrive); set_pconfig(local_channel(),'system','activitypub',$activitypub); set_pconfig(local_channel(),'system','autoperms',$autoperms); + set_pconfig(local_channel(),'system','permit_all_mentions',$permit_all_mentions); $r = q("update channel set channel_name = '%s', channel_pageflags = %d, channel_timezone = '%s', channel_location = '%s', channel_notifyflags = %d, channel_max_anon_mail = %d, channel_max_friend_req = %d, channel_expire_days = %d $set_perms where channel_id = %d", dbesc($username), @@ -613,6 +615,7 @@ class Channel { '$apconfig' => $apconfig, '$apheader' => $apheader, '$apdoc' => $apdoc, + '$close' => t('Close'), '$h_not' => t('Notifications'), '$activity_options' => t('By default post a status message when:'), '$post_newfriend' => array('post_newfriend', t('accepting a friend request'), $post_newfriend, '', $yes_no), @@ -651,7 +654,7 @@ class Channel { '$vnotify16' => ((is_site_admin()) ? array('vnotify16', t('Reported content'), ($vnotify & VNOTIFY_REPORTS), VNOTIFY_REPORTS, '', $yes_no) : [] ), '$mailhost' => [ 'mailhost', t('Email notification hub (hostname)'), get_pconfig(local_channel(),'system','email_notify_host',App::get_hostname()), sprintf( t('If your channel is mirrored to multiple locations, set this to your preferred location. This will prevent duplicate email notifications. Example: %s'),App::get_hostname()) ], '$always_show_in_notices' => array('always_show_in_notices', t('Show new wall posts, private messages and connections under Notices'), $always_show_in_notices, 1, '', $yes_no), - + '$permit_all_mentions' => [ 'permit_all_mentions', t('Accept messages from strangers which mention me'), get_pconfig(local_channel(),'system','permit_all_mentions'), t('This setting supercedes normal permissions'), $yes_no ], '$evdays' => array('evdays', t('Notify me of events this many days in advance'), $evdays, t('Must be greater than 0')), '$basic_addon' => $plugin['basic'], '$sec_addon' => $plugin['security'], diff --git a/include/items.php b/include/items.php index decbb04bb..789144f15 100644 --- a/include/items.php +++ b/include/items.php @@ -2657,7 +2657,6 @@ function tag_deliver($uid, $item_id) { 'verb' => ACTIVITY_TAG, 'otype' => 'item' )); - } } if ($is_collection && $pterms) { @@ -2775,9 +2774,45 @@ function tgroup_check($uid, $item) { return true; } + // return true if we are mentioned and we permit delivery of mentions from strangers + + if (PConfig::Get($uid, 'system','permit_all_mentions') && i_am_mentioned($u,$item)) { + return true; + } + return false; } + +function i_am_mentioned($channel,$item) { + + $link = $channel['xchan_url']; + + $body = preg_replace('/\[share(.*?)\[\/share\]/','',$item['body']); + + $tagged = false; + $matches = []; + + $terms = get_terms_oftype($item['term'],TERM_MENTION); + if ($terms) { + foreach ($terms as $term) { + if ($link === $term['url']) { + $pattern = '/[\!@]\!?\[[uz]rl\=' . preg_quote($term['url'],'/') . '\]' . preg_quote($term['term'],'/') . '\[\/[uz]rl\]/'; + if (preg_match($pattern,$body,$matches)) { + $tagged = true; + } + $pattern = '/\[[uz]rl\=' . preg_quote($term['url'],'/') . '\][\!@](.*?)\[\/[uz]rl\]/'; + if (preg_match($pattern,$body,$matches)) { + $tagged = true; + } + } + } + } + return $tagged; +} + + + /** * Sourced and tag-delivered posts are re-targetted for delivery to the connections of the channel * receiving the post. This starts the second delivery chain, by resetting permissions and ensuring diff --git a/include/text.php b/include/text.php index 7520c0321..41edc399f 100644 --- a/include/text.php +++ b/include/text.php @@ -11,7 +11,6 @@ use Zotlabs\Lib\SvgSanitizer; use Michelf\MarkdownExtra; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; -use Emoji; require_once("include/bbcode.php"); diff --git a/view/tpl/settings.tpl b/view/tpl/settings.tpl index 271c88818..3a67adf2d 100755 --- a/view/tpl/settings.tpl +++ b/view/tpl/settings.tpl @@ -51,6 +51,7 @@ {{$autoperms}} {{$anymention}} {{include file="field_select.tpl" field=$comment_perms}} + {{include file="field_checkbox.tpl" field=$permit_all_mentions}}
@@ -61,7 +62,7 @@