-
Notifications
You must be signed in to change notification settings - Fork 593
/
Comments.php
76 lines (71 loc) · 3.26 KB
/
Comments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* TeKit Plugin
*
* @copyright Copyright (c) 2013 Binjoo (http://binjoo.net)
* @license GNU General Public License 2.0
*
*/
class TeKit_Comments extends Widget_Abstract_Comments implements Widget_Interface_Do {
public function __construct($request, $response, $params = NULL) {
parent::__construct($request, $response, $params);
}
private function clearPush(){
$this->row = array();
$this->length = 0;
$this->stack = array();
return $this;
}
public function MostCommentors($days = NULL, $number = 10, $ignore = true){
$sql = $this->db->select('table.comments.author, table.comments.mail, table.comments.url, table.comments.created, count(1) as cnt')->from('table.comments')
->where('table.comments.status = ?','approved')
->group('table.comments.author, table.comments.mail')
->limit($number)
->order('cnt', Typecho_Db::SORT_DESC);
if($days){
$sql->where('table.comments.created >= ?', $this->options->gmtTime - (24 * 60 * 60 * $days));
}
if($ignore){
$sql->where('table.comments.ownerId <> table.comments.authorId');
}
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
return $this;
}
public function MostSofaCommentors($days = NULL, $number = 10, $ignore = true){
$prefix = $this->db->getPrefix();
$sql = "select author, url, mail, created, count(*) as cnt from (SELECT a.author, a.url, a.mail, a.created, min(a.created) FROM " . $prefix . "comments a, " . $prefix . "contents b WHERE b.status = 'publish' and b.type = 'post' and b.commentsNum <> 0 ";
if($days){
$sql = $sql."and a.created >= '". ($this->options->gmtTime - (24 * 60 * 60 * $days)) ."' ";
}
if($ignore){
$sql = $sql."and a.ownerId <> a.authorId";
}
$sql = $sql." and a.cid = b.cid group by a.cid) c group by c.author order by cnt desc limit " . $number;
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
return $this;
}
public function CommentorNumber($author, $mail, $days = 30){
$sql = $this->db->select(array('count(1)' => 'cnt'))->from('table.comments')
->where('table.comments.status = ?','approved')
->where('table.comments.author = ?', $author)
->where('table.comments.mail = ?', $mail)
->order('table.comments.created', Typecho_Db::SORT_DESC);
if($days){
$sql->where('table.comments.created >= ?', $this->options->gmtTime - (24 * 60 * 60 * $days));
}
return $this->clearPush()->db->fetchObject($sql)->cnt;
}
public function CommentorComments($author, $mail, $days = 30){
$sql = $this->select()
->where('table.comments.status = ?','approved')
->where('table.comments.author = ?', $author)
->where('table.comments.mail = ?', $mail)
->order('table.comments.created', Typecho_Db::SORT_DESC);
if($days){
$sql->where('table.comments.created >= ?', $this->options->gmtTime - (24 * 60 * 60 * $days));
}
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
return $this;
}
public function action() {}
}