Filter comments by visibility

Hello,

i am currently trying to implement this kirby comments plugin by @florianpircher.

I would like comments to be invisible by default while being able to make them visible manually via the panel.

I have added the option: c::set('comments.pages.comment.visible', false); in my config.php file which makes comments invisible by default but cannot find a way to load only visible comments in the comments list.

What I am trying to do is something like this:

<?php if (!$comments->isEmpty()): ?>

	<h2>Comments</h2>
	
	<?php foreach ($comments as $comment): ?>
	    
	    <?php if ($comment->isVisible()): ?>
	    
		<article>
            <?php echo $comment->message() ?>
		</article>
		
		<?php endif ?>
		
	<?php endforeach ?>
	
<?php endif ?>

Of course the following line does not work:

<?php if ($comment->isVisible()): ?>

Can anyone suggest a way this could be done?

Thanks in advance!

Hm, you could try to filter them by visibility status in the comments-list.php snippet:

$comments = $page->comments()->visible();

(https://github.com/Addpixel/KirbyComments/blob/master/snippets/comments-list.php, #14)

But I’m not sure if this is possible because I don’t know if $comments is a pages collection or not.

Hi @phrase!

I assume you want to use the visible/invisible state for moderating comments.

The comments.pages.comment.visible configuration was added to allow site admins to adapt Kirby Comments to their needs. Many plugins (e.g. search, sitemap, …) do not provide a filter for blocking specific page-types. Because Kirby Comments stores the comments as subpages comments would often show up in search results or as random-page or in some other form, which is why this configuration was added. (relevant issue on GitHub)

Over the development of the plugin I got a lot of requests for a moderation system. As you have noticed, making pages visible/invisible would also make for a great interface for moderation. Sadly, this now conflicts with the comments.pages.comment.visible config, so I can not use visibility for moderation anymore :pensive:

Other interfaces—like custom fields—work, but are more cumbersome to work with on the panel. My plan is to deprecate the comments.pages.comment.visible config and drop it in version 2, which will use visibility for moderation and even offer a moderation widget. This has been the #1 feature request and most of the work is already done, but with the current Kirby-API I don’t have a secure and reliable method of implementing it. Hopefully Kirby 3 will define a stable plugin–panel interface with which such a project could be done.

Feel free to offer any suggestions regarding how you would like the moderation system to look and feel. :slight_smile:


@texnixe $page->comments()->visible() is not possible, because $page->comments() is not a page collection, but a custom type implementing the Iterator interface. (see the Comments type definition and docs on all methods of an individual Comment)

@florianpircher Yeah, I was afraid that was the case.

@texnixe @florianpircher Thanks for your quick response!

You are right. A way to moderate comments was what I was looking for.

Although it makes perfect sense to me to use page visibility for this, maybe for a person less familiar with kirby (e.g. an editor) it would be best to use some more straightforward interface and wording like you have done with the dashboard widget demo.

For the time being I will try to find a solution using custom fields.