From f9fea6b5e6b2a5ae4bd6719b1eb76cb2a6fdea5a Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sun, 12 Mar 2023 19:41:15 -0700 Subject: [PATCH] refactor "permit-all-likes" --- Code/Lib/Activity.php | 2 +- Code/Module/Settings/Channel.php | 3 +++ include/items.php | 2 +- view/tpl/settings.tpl | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 9a324716d..7cb2965a3 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -4055,7 +4055,7 @@ class Activity $allowed = perm_is_allowed($channel['channel_id'], $item['author_xchan'], 'post_comments'); // Allow likes from strangers if permitted to do so. These are difficult (but not impossible) to spam. - if ($item['verb'] === 'Like' && PConfig::Get($channel['channel_id'], 'system', 'permit_all_likes', true)) { + if ($item['verb'] === 'Like' && PConfig::Get($channel['channel_id'], 'system', 'permit_all_likes') && $item['obj_type'] === 'Note') { $allowed = true; } diff --git a/Code/Module/Settings/Channel.php b/Code/Module/Settings/Channel.php index 4ce83ca0f..4b2d553cf 100644 --- a/Code/Module/Settings/Channel.php +++ b/Code/Module/Settings/Channel.php @@ -95,6 +95,7 @@ class Channel $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); + $permit_all_likes = (($_POST['permit_all_likes'] == 1) ? 1 : 0); $close_comment_days = (($_POST['close_comments']) ? intval($_POST['close_comments']) : 0); set_pconfig(local_channel(), 'system', 'close_comments', $close_comment_days ? $close_comment_days . ' days' : ''); @@ -176,6 +177,7 @@ class Channel set_pconfig(local_channel(), 'system', 'autoperms', $this->autoperms); set_pconfig(local_channel(), 'system', 'tag_username', $tag_username); set_pconfig(local_channel(), 'system', 'permit_all_mentions', $permit_all_mentions); + set_pconfig(local_channel(), 'system', 'permit_all_likes', $permit_all_likes); set_pconfig(local_channel(), 'system', 'unless_mention_count', $unless_mention_count); set_pconfig(local_channel(), 'system', 'unless_tag_count', $unless_tag_count); set_pconfig(local_channel(), 'system', 'noindex', $noindex); @@ -533,6 +535,7 @@ class Channel '$desktop_notifications_request' => t('Grant permission'), '$mailhost' => ['mailhost', t('Email notifications sent from (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())], '$permit_all_mentions' => ['permit_all_mentions', t('Accept messages from strangers which mention you'), get_pconfig(local_channel(), 'system', 'permit_all_mentions'), t('This setting bypasses normal permissions'), $yes_no], + '$permit_all_likes' => ['permit_all_likes', t('Accept likes from strangers'), get_pconfig(local_channel(), 'system', 'permit_all_likes'), t('This setting bypasses normal permissions'), $yes_no], '$followed_tags' => ['followed_tags', t('Accept messages from strangers which include any of the following hashtags'), $followed, t('comma separated, do not include the #')], '$unless_mention_count' => ['unless_mention_count', t('Unless more than this many channels are mentioned'), $mention_count, t('0 for unlimited')], '$unless_tag_count' => ['unless_tag_count', t('Unless more than this many hashtags are used'), $tag_count, t('0 for unlimited')], diff --git a/include/items.php b/include/items.php index 36c8a34bb..833b26776 100644 --- a/include/items.php +++ b/include/items.php @@ -2823,7 +2823,7 @@ function tgroup_check($uid, $item) { return true; } - if (PConfig::Get($uid, 'system','permit_all_likes',true) && $item['verb'] === 'Like') { + if (PConfig::Get($uid, 'system','permit_all_likes') && $item['verb'] === 'Like' && $item['obj_type'] === 'Note') { return true; } diff --git a/view/tpl/settings.tpl b/view/tpl/settings.tpl index 3fc6ff97c..c4d245442 100755 --- a/view/tpl/settings.tpl +++ b/view/tpl/settings.tpl @@ -57,6 +57,7 @@ {{include file="field_select.tpl" field=$mail_perms}} {{include file="field_select.tpl" field=$view_contact_perms}} {{include file="field_select.tpl" field=$search_perms}} + {{include file="field_checkbox.tpl" field=$permit_all_likes}} {{include file="field_checkbox.tpl" field=$permit_all_mentions}} {{include file="field_input.tpl" field=$unless_mention_count}} {{include file="field_input.tpl" field=$followed_tags}}