From 7af12a1f7e4378394e7f08c40a579e6738748af5 Mon Sep 17 00:00:00 2001 From: nobody Date: Mon, 23 Nov 2020 19:14:44 -0800 Subject: [PATCH] per-post comment control: select comment allowed audience and comments_closed date --- Zotlabs/Access/Permissions.php | 4 +-- Zotlabs/Lib/Apps.php | 1 + Zotlabs/Module/Comment_control.php | 28 +++++++++++++++ Zotlabs/Module/Item.php | 9 +++-- app/comment_control.apd | 6 ++++ include/conversation.php | 58 ++++++++++++++++++++++++++++++ view/tpl/jot-header.tpl | 17 +++++++++ view/tpl/jot.tpl | 12 ++++++- 8 files changed, 127 insertions(+), 8 deletions(-) create mode 100644 Zotlabs/Module/Comment_control.php create mode 100644 app/comment_control.apd diff --git a/Zotlabs/Access/Permissions.php b/Zotlabs/Access/Permissions.php index d82a784dd..ee588c5d1 100644 --- a/Zotlabs/Access/Permissions.php +++ b/Zotlabs/Access/Permissions.php @@ -58,8 +58,8 @@ class Permissions { 'view_contacts' => t('Grant viewing access to your address book (connections)'), 'view_storage' => t('Grant viewing access to your file storage and photos'), 'post_wall' => t('Grant permission to post on your channel (wall) page'), - 'send_stream' => t('Accept delivery of their posts and all comments to their posts'), - 'post_comments' => t('Accept delivery of their comments and likes on your posts'), + 'send_stream' => t('Accept delivery of their posts and all comments to their posts from'), + 'post_comments' => t('Accept delivery of comments and likes on your posts from'), 'write_storage' => t('Grant upload permissions to your file storage and photos'), 'republish' => t('Grant permission to republish/mirror your posts'), 'moderated' => t('Accept comments and wall posts only after approval (moderation)'), diff --git a/Zotlabs/Lib/Apps.php b/Zotlabs/Lib/Apps.php index c4b35c401..b8d6d9b20 100644 --- a/Zotlabs/Lib/Apps.php +++ b/Zotlabs/Lib/Apps.php @@ -347,6 +347,7 @@ class Apps { 'Tasks' => t('Tasks'), 'Tagadelic' => t('Tagadelic'), 'No Comment' => t('No Comment'), + 'Comment Control' => t('Comment Control'), 'Directory' => t('Directory'), 'Help' => t('Help'), 'Mail' => t('Mail'), diff --git a/Zotlabs/Module/Comment_control.php b/Zotlabs/Module/Comment_control.php new file mode 100644 index 000000000..884096e09 --- /dev/null +++ b/Zotlabs/Module/Comment_control.php @@ -0,0 +1,28 @@ +' . $desc . ''; + + if(! ( local_channel() && Apps::system_app_installed(local_channel(),'Comment Control'))) { + return $text; + } + + $desc = t('This app is installed. A button to control comments may be found below the post editor.'); + + $text = '
' . $desc . '
'; + + return $text; + + } +} diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 2ffbe26c4..584d4f43d 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -293,7 +293,6 @@ class Item extends Controller { $token = EMPTY_STR; $datarray = []; - /** * Is this a reply to something? */ @@ -302,6 +301,7 @@ class Item extends Controller { $parent_mid = ((x($_REQUEST,'parent_mid')) ? trim($_REQUEST['parent_mid']) : ''); $hidden_mentions = ((x($_REQUEST,'hidden_mentions')) ? trim($_REQUEST['hidden_mentions']) : ''); + $comments_closed = ((x($_REQUEST,'comments_closed')) ? datetime_convert(date_default_timezone_get(),'UTC',$_REQUEST['comments_closed']) : NULL_DATE); /** * Who is viewing this page and posting this thing @@ -334,8 +334,8 @@ class Item extends Controller { $api_source = ((x($_REQUEST,'api_source') && $_REQUEST['api_source']) ? true : false); - $nocomment = intval($_REQUEST['nocomment']); + $nocomment = intval($_REQUEST['nocomment']); $is_poll = ((trim($_REQUEST['poll_answers'][0]) != '' && trim($_REQUEST['poll_answers'][1]) != '') ? true : false); // 'origin' (if non-zero) indicates that this network is where the message originated, @@ -644,8 +644,8 @@ class Item extends Controller { $acl = new AccessControl($channel); $view_policy = PermissionLimits::Get($channel['channel_id'],'view_stream'); - $comment_policy = PermissionLimits::Get($channel['channel_id'],'post_comments'); - + $comment_policy = ((isset($_REQUEST['comments_from'])) ? intval($_REQUEST['comments_from']) : PermissionLimits::Get($channel['channel_id'],'post_comments')); + $public_policy = ((x($_REQUEST,'public_policy')) ? escape_tags($_REQUEST['public_policy']) : map_scope($view_policy,true)); if($webpage) $public_policy = ''; @@ -1154,7 +1154,6 @@ class Item extends Controller { $obj = $this->extract_bb_poll_data($body,[ 'item_private' => $private, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_contact_deny ]); } - $comments_closed = NULL_DATE; if ($obj) { $obj['url'] = $mid; diff --git a/app/comment_control.apd b/app/comment_control.apd new file mode 100644 index 000000000..8a9eef197 --- /dev/null +++ b/app/comment_control.apd @@ -0,0 +1,6 @@ +version: 1 +url: $baseurl/comment_control +requires: local_channel +name: Comment Control +photo: icon:comment-o +categories: Social diff --git a/include/conversation.php b/include/conversation.php index f3e6d8178..d644f563b 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -5,6 +5,9 @@ use Zotlabs\Lib\LibBlock; use Zotlabs\Lib\ThreadStream; use Zotlabs\Lib\ThreadItem; use Zotlabs\Lib\Chatroom; +use Zotlabs\Access\Permissions; +use Zotlabs\Access\PermissionLimits; + function item_extract_images($body) { @@ -1248,6 +1251,12 @@ function z_status_editor($a, $x, $popup = false) { if(x($x, 'disable_comments')) $feature_nocomment = false; + + $feature_comment_control = Apps::system_app_installed($x['profile_uid'], 'Comment Control'); + if(x($x, 'disable_comment_control')) + $feature_comment_control = false; + + $feature_expire = ((Apps::system_app_installed($x['profile_uid'], 'Expire Posts') && (! $webpage)) ? true : false); if(x($x, 'hide_expire')) $feature_expire = false; @@ -1366,6 +1375,48 @@ function z_status_editor($a, $x, $popup = false) { else $catsenabled = ((Apps::system_app_installed($x['profile_uid'], 'Categories') && (! $webpage)) ? 'categories' : ''); + + // we only need the comment_perms for the editor, but this logic is complicated enough (from Settings/Channel) + // that we will just duplicate the entire code block + + $global_perms = Permissions::Perms(); + + $permiss = []; + + $perm_opts = [ + array( t('Nobody except yourself'), 0), + array( t('Only those you specifically allow'), PERMS_SPECIFIC), + array( t('Approved connections'), PERMS_CONTACTS), + array( t('Any connections'), PERMS_PENDING), + array( t('Anybody on this website'), PERMS_SITE), + array( t('Anybody in this network'), PERMS_NETWORK), + array( t('Anybody authenticated'), PERMS_AUTHED), + array( t('Anybody on the internet'), PERMS_PUBLIC) + ]; + + $limits = PermissionLimits::Get(local_channel()); + $anon_comments = get_config('system','anonymous_comments',true); + + foreach($global_perms as $k => $perm) { + $options = []; + $can_be_public = ((strstr($k,'view') || ($k === 'post_comments' && $anon_comments)) ? true : false); + foreach($perm_opts as $opt) { + if($opt[1] == PERMS_PUBLIC && (! $can_be_public)) + continue; + $options[$opt[1]] = $opt[0]; + } + if($k === 'view_stream') { + $options = [$perm_opts[7][1] => $perm_opts[7][0]]; + } + if($k === 'post_comments') { + $comment_perms = [ $k, t('Accept delivery of comments and likes on this post from'), $limits[$k],'',$options ]; + } + else { + $permiss[] = array($k,$perm,$limits[$k],'',$options); + } + } + + // avoid illegal offset errors if(! array_key_exists('permissions',$x)) $x['permissions'] = [ 'allow_cid' => '', 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '' ]; @@ -1423,6 +1474,11 @@ function z_status_editor($a, $x, $popup = false) { '$nocommenttitle' => t('Disable comments'), '$nocommenttitlesub' => t('Toggle comments'), '$feature_nocomment' => $feature_nocomment, + '$feature_comment_control' => $feature_comment_control, + '$commctrl' => t('Comment Control'), + '$comments_closed' => (($x['item']['comments_closed']) ? $x['item']['comments_closed'] : ''), + '$commclosedate' => t('Disable comments after (date)'), + '$comment_perms' => $comment_perms, '$nocomment' => ((array_key_exists('item',$x)) ? $x['item']['item_nocomment'] : 0), '$clearloc' => $clearloc, '$title' => ((x($x, 'title')) ? htmlspecialchars($x['title'], ENT_COMPAT,'UTF-8') : ''), @@ -1467,6 +1523,8 @@ function z_status_editor($a, $x, $popup = false) { '$cipher' => $cipher, '$expiryModalOK' => t('OK'), '$expiryModalCANCEL' => t('Cancel'), + '$commModalOK' => t('OK'), + '$commModalCANCEL' => t('Cancel'), '$linkModalOK' => t('OK'), '$linkModalCANCEL' => t('Cancel'), '$close' => t('Close'), diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index f1ac78298..c36d23574 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -272,6 +272,23 @@ var activeCommentText = ''; }) } + function jotGetCommCtrl() { + $('#commModal').modal(); + $('#comm-modal-OKButton').on('click', function() { + var post_comments = $('#post_comments').val(); + if (post_comments && post_comments.length) { + $('#jot-commfrom').val(post_comments); + } + var reply=$('#commclose-date').val(); + if(reply && reply.length) { + $('#jot-commclosed').val(reply); + } + $('#commModal').modal('hide'); + + }) + } + + function jotGetPubDate() { $('#createdModal').modal(); $('#created-modal-OKButton').on('click', function() { diff --git a/view/tpl/jot.tpl b/view/tpl/jot.tpl index 50207037f..990b129ec 100755 --- a/view/tpl/jot.tpl +++ b/view/tpl/jot.tpl @@ -18,6 +18,8 @@ + + @@ -146,6 +148,13 @@ {{/if}} + + {{if $feature_comment_control}} + + {{/if}} + {{if $feature_future}}