1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-14 02:34:24 +02:00
This commit is contained in:
Ryan Cramer
2020-05-14 15:11:11 -04:00
parent c191a84f7a
commit ebe352d5cc
2 changed files with 22 additions and 2 deletions

View File

@@ -60,6 +60,12 @@ class CommentList extends Wire implements CommentListInterface {
*/
protected $field;
/**
* @var bool|null
*
*/
protected $editable = null;
/**
* Default options that may be overridden from constructor
*
@@ -175,7 +181,6 @@ class CommentList extends Wire implements CommentListInterface {
public function getReplies($commentID) {
if(is_object($commentID)) $commentID = $commentID->id;
$commentID = (int) $commentID;
$admin = $this->options['admin'];
$replies = array();
$comments = $this->comments;
if($commentID && $comments->data('selectors') && $this->comment && $this->comment->id == $commentID) {
@@ -188,7 +193,7 @@ class CommentList extends Wire implements CommentListInterface {
}
foreach($comments as $c) {
if($c->parent_id != $commentID) continue;
if(!$admin && $c->status < Comment::statusApproved) continue;
if(!$this->allowRenderItem($c)) continue;
$replies[] = $c;
}
$this->numReplies[$commentID] = count($replies);
@@ -261,6 +266,7 @@ class CommentList extends Wire implements CommentListInterface {
if(!count($comments)) return $out;
foreach($comments as $comment) {
if(!$this->allowRenderItem($comment)) continue;
$this->comment = $comment;
$out .= $this->renderItem($comment, array('depth' => $depth));
}
@@ -334,6 +340,19 @@ class CommentList extends Wire implements CommentListInterface {
return $out;
}
/**
* Allow comment to be rendered in list?
*
* @param Comment $comment
* @return bool
*
*/
protected function allowRenderItem(Comment $comment) {
if($this->editable === null) $this->editable = $this->options['admin'] && $this->page->editable();
if($this->editable || $comment->status >= Comment::statusApproved) return true;
return false;
}
/**
* Render the comment

View File

@@ -131,6 +131,7 @@ class CommentListCustom extends CommentList {
$out = $parent_id ? '' : $this->renderCheckActions();
$comments = $this->options['depth'] > 0 ? $this->getReplies($parent_id) : $this->comments;
foreach($comments as $comment) {
if(!$this->allowRenderItem($comment)) continue;
$this->comment = $comment;
$out .= $this->renderItem($comment, array('depth' => $depth));
}