mirror of
https://git.beihong.wang/wangbeihong/blog-source.git
synced 2026-04-24 02:53:05 +08:00
initial
This commit is contained in:
60
var/Widget/Comments/Recent.php
Executable file
60
var/Widget/Comments/Recent.php
Executable file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Widget\Comments;
|
||||
|
||||
use Typecho\Config;
|
||||
use Typecho\Db;
|
||||
use Typecho\Db\Exception;
|
||||
use Widget\Base\Comments;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近评论组件
|
||||
*
|
||||
* @category typecho
|
||||
* @package Widget
|
||||
* @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
|
||||
* @license GNU General Public License 2.0
|
||||
*/
|
||||
class Recent extends Comments
|
||||
{
|
||||
/**
|
||||
* @param Config $parameter
|
||||
*/
|
||||
protected function initParameter(Config $parameter)
|
||||
{
|
||||
$parameter->setDefault(
|
||||
['pageSize' => $this->options->commentsListSize, 'parentId' => 0, 'ignoreAuthor' => false]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行函数
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$select = $this->select()->limit($this->parameter->pageSize)
|
||||
->where('table.comments.status = ?', 'approved')
|
||||
->order('table.comments.coid', Db::SORT_DESC);
|
||||
|
||||
if ($this->parameter->parentId) {
|
||||
$select->where('cid = ?', $this->parameter->parentId);
|
||||
}
|
||||
|
||||
if ($this->options->commentsShowCommentOnly) {
|
||||
$select->where('type = ?', 'comment');
|
||||
}
|
||||
|
||||
/** 忽略作者评论 */
|
||||
if ($this->parameter->ignoreAuthor) {
|
||||
$select->where('ownerId <> authorId');
|
||||
}
|
||||
|
||||
$this->db->fetchAll($select, [$this, 'push']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user