Remove comment link if status is not approved (#1712)
* remove comment link if status is not approved * fix stack * fix: remove link in admin panel when comment status is not approved * fix: comments page nav * fix comment redirect url * fix comment anchor * fix waiting comment display * fix: convert waiting to unapproved
This commit is contained in:
@@ -110,6 +110,6 @@ abstract class PageNavigator
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
throw new Exception(get_class($this) . ':' . __METHOD__, 500);
|
||||
throw new Exception('Method Not Implemented', 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
* @property string $type
|
||||
* @property string status
|
||||
* @property int $parent
|
||||
* @property int $commentPage
|
||||
* @property Date $date
|
||||
* @property string $dateWord
|
||||
* @property string $theId
|
||||
@@ -61,6 +62,8 @@ class Comments extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
switch ($key) {
|
||||
case 'permalink':
|
||||
return $this->parentContent->path;
|
||||
case 'commentPage':
|
||||
return $this->commentPage;
|
||||
default:
|
||||
return '{' . $key . '}';
|
||||
}
|
||||
@@ -396,14 +399,13 @@ class Comments extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前评论链接
|
||||
* 获取当前评论页码
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
* @return int
|
||||
*/
|
||||
protected function ___permalink(): string
|
||||
protected function ___commentPage(): int
|
||||
{
|
||||
if ($this->options->commentsPageBreak && 'approved' == $this->status) {
|
||||
if ($this->options->commentsPageBreak) {
|
||||
$coid = $this->coid;
|
||||
$parent = $this->parent;
|
||||
|
||||
@@ -420,7 +422,13 @@ class Comments extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
}
|
||||
|
||||
$select = $this->db->select('coid', 'parent')
|
||||
->from('table.comments')->where('cid = ? AND status = ?', $this->cid, 'approved')
|
||||
->from('table.comments')
|
||||
->where(
|
||||
'cid = ? AND (status = ? OR coid = ?)',
|
||||
$this->cid,
|
||||
'approved',
|
||||
$this->status !== 'approved' ? $this->coid : 0
|
||||
)
|
||||
->where('coid ' . ('DESC' == $this->options->commentsOrder ? '>=' : '<=') . ' ?', $coid)
|
||||
->order('coid');
|
||||
|
||||
@@ -441,12 +449,24 @@ class Comments extends Base implements QueryInterface, RowFilterInterface, Prima
|
||||
}
|
||||
}
|
||||
|
||||
$currentPage = ceil($total / $this->options->commentsPageSize);
|
||||
return ceil($total / $this->options->commentsPageSize);
|
||||
}
|
||||
|
||||
$pageRow = ['permalink' => $this->parentContent->path, 'commentPage' => $currentPage];
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前评论链接
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function ___permalink(): string
|
||||
{
|
||||
if ($this->options->commentsPageBreak) {
|
||||
return Router::url(
|
||||
'comment_page',
|
||||
$pageRow,
|
||||
$this,
|
||||
$this->options->index
|
||||
) . '#' . $this->theId;
|
||||
}
|
||||
|
||||
@@ -151,4 +151,16 @@ class Admin extends Comments
|
||||
$cid = $this->request->is('cid') ? $this->request->filter('int')->get('cid') : $this->cid;
|
||||
return From::allocWithAlias($cid, ['cid' => $cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function ___permalink(): string
|
||||
{
|
||||
if ('approved' === $this->status) {
|
||||
return parent::___permalink();
|
||||
}
|
||||
|
||||
return '#' . $this->theId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,16 +99,13 @@ class Archive extends Comments
|
||||
return;
|
||||
}
|
||||
|
||||
$commentsAuthor = Cookie::get('__typecho_remember_author');
|
||||
$commentsMail = Cookie::get('__typecho_remember_mail');
|
||||
$select = $this->select()->where('table.comments.cid = ?', $this->parameter->parentId)
|
||||
$unapprovedCommentId = intval(Cookie::get('__typecho_unapproved_comment', 0));
|
||||
$select = $this->select()->where('cid = ?', $this->parameter->parentId)
|
||||
->where(
|
||||
'table.comments.status = ? OR (table.comments.author = ?'
|
||||
. ' AND table.comments.mail = ? AND table.comments.status = ?)',
|
||||
'status = ? OR (coid = ? AND status <> ?)',
|
||||
'approved',
|
||||
$commentsAuthor,
|
||||
$commentsMail,
|
||||
'waiting'
|
||||
$unapprovedCommentId,
|
||||
'approved'
|
||||
);
|
||||
|
||||
if ($this->options->commentsShowCommentOnly) {
|
||||
@@ -176,12 +173,11 @@ class Archive extends Comments
|
||||
($this->currentPage - 1) * $this->options->commentsPageSize,
|
||||
$this->options->commentsPageSize
|
||||
);
|
||||
|
||||
/** 评论置位 */
|
||||
$this->length = count($this->stack);
|
||||
$this->row = $this->length > 0 ? current($this->stack) : [];
|
||||
}
|
||||
|
||||
/** 评论置位 */
|
||||
$this->length = count($this->stack);
|
||||
$this->row = $this->length > 0 ? current($this->stack) : [];
|
||||
reset($this->stack);
|
||||
}
|
||||
|
||||
@@ -241,7 +237,10 @@ class Archive extends Comments
|
||||
}
|
||||
|
||||
$template = array_merge($default, $config);
|
||||
$query = Router::url('comment_page', $this, $this->options->index);
|
||||
$query = Router::url('comment_page', [
|
||||
'permalink' => $this->parameter->parentContent->path,
|
||||
'commentPage' => '{commentPage}'
|
||||
], $this->options->index);
|
||||
|
||||
self::pluginHandle()->trigger($hasNav)->call(
|
||||
'pageNav',
|
||||
@@ -360,7 +359,7 @@ class Archive extends Comments
|
||||
$singleCommentOptions->afterDate();
|
||||
?></time>
|
||||
</a>
|
||||
<?php if ('waiting' == $this->status) { ?>
|
||||
<?php if ('approved' !== $this->status) { ?>
|
||||
<em class="comment-awaiting-moderation"><?php $singleCommentOptions->commentStatus(); ?></em>
|
||||
<?php } ?>
|
||||
</div>
|
||||
@@ -465,21 +464,6 @@ class Archive extends Comments
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前评论链接
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function ___permalink(): string
|
||||
{
|
||||
if ($this->options->commentsPageBreak) {
|
||||
$pageRow = ['permalink' => $this->parentContent->path, 'commentPage' => $this->currentPage];
|
||||
return Router::url('comment_page', $pageRow, $this->options->index) . '#' . $this->theId;
|
||||
}
|
||||
|
||||
return $this->parentContent->permalink . '#' . $this->theId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 子评论
|
||||
*
|
||||
@@ -501,6 +485,16 @@ class Archive extends Comments
|
||||
return $this->levels > $this->options->commentsMaxNestingLevels - 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载评论页码获取
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function ___commentPage(): int
|
||||
{
|
||||
return $this->currentPage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重载内容获取
|
||||
*
|
||||
|
||||
@@ -270,7 +270,11 @@ class Feedback extends Comments implements ActionInterface
|
||||
/** 评论完成接口 */
|
||||
self::pluginHandle()->call('finishComment', $this);
|
||||
|
||||
$this->response->goBack('#' . $this->theId);
|
||||
if ($this->status !== 'approved') {
|
||||
Cookie::set('__typecho_unapproved_comment', $commentId);
|
||||
}
|
||||
|
||||
$this->response->redirect($this->permalink);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user