Skip to content

Commit 7446084

Browse files
committed
Squashed 'TeKit/' content from commit 6f26ae7
git-subtree-dir: TeKit git-subtree-split: 6f26ae7fd9ce5e5a529a58815cbf554f64d09d9b
0 parents  commit 7446084

File tree

4 files changed

+233
-0
lines changed

4 files changed

+233
-0
lines changed

Comments.php

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

Contents.php

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* TeKit Plugin
4+
*
5+
* @copyright Copyright (c) 2013 Binjoo (http://binjoo.net)
6+
* @license GNU General Public License 2.0
7+
*
8+
*/
9+
class TeKit_Contents extends Widget_Abstract_Contents implements Widget_Interface_Do {
10+
public function __construct($request, $response, $params = NULL) {
11+
parent::__construct($request, $response, $params);
12+
}
13+
/**
14+
* 清空堆栈信息
15+
*/
16+
private function clearPush(){
17+
$this->row = array();
18+
$this->length = 0;
19+
$this->stack = array();
20+
return $this;
21+
}
22+
23+
public function push(array $value) {
24+
//$value = $this->filter($value);
25+
return parent::push($value);
26+
}
27+
28+
public function Random($number = 10){
29+
$sql = $this->select()
30+
->where('table.contents.status = ?', 'publish')
31+
->where('table.contents.created <= ?', $this->options->gmtTime)
32+
->where('table.contents.type = ?', 'post')
33+
->limit($number)
34+
->order('RAND()');
35+
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
36+
return $this;
37+
}
38+
39+
public function MostCommented($number = 10){
40+
$sql = $this->select()
41+
->where('table.contents.status = ?', 'publish')
42+
->where('table.contents.type = ?', 'post')
43+
->where('table.contents.created <= ?', $this->options->gmtTime)
44+
->limit($number)
45+
->order('commentsNum',Typecho_Db::SORT_DESC);
46+
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
47+
return $this;
48+
}
49+
50+
public function HistoryToday($number = 10){
51+
$year = date('Y', $this->options->gmtTime);
52+
$month = date('m', $this->options->gmtTime);
53+
$day = date('j', $this->options->gmtTime);
54+
55+
$sql = $this->select()
56+
->where('table.contents.status = ?', 'publish')
57+
->where('table.contents.created <= ?', $this->options->gmtTime)
58+
->where('year(FROM_UNIXTIME(table.contents.created)) <> ?', $year)
59+
->where('month(FROM_UNIXTIME(table.contents.created)) = ?', $month)
60+
->where('day(FROM_UNIXTIME(table.contents.created)) = ?', $day)
61+
->where('table.contents.type = ?', 'post')
62+
->limit($number)
63+
->order('table.contents.created', Typecho_Db::SORT_DESC);
64+
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
65+
return $this;
66+
}
67+
68+
public function HistoryTomonth($number = 10){
69+
$year = date('Y', $this->options->gmtTime);
70+
$month = date('m', $this->options->gmtTime);
71+
72+
$sql = $this->select()
73+
->where('table.contents.status = ?', 'publish')
74+
->where('table.contents.created <= ?', $this->options->gmtTime)
75+
->where('year(FROM_UNIXTIME(table.contents.created)) <> ?', $year)
76+
->where('month(FROM_UNIXTIME(table.contents.created)) = ?', $month)
77+
->where('table.contents.type = ?', 'post')
78+
->limit($number)
79+
->order('table.contents.created', Typecho_Db::SORT_DESC);
80+
$this->clearPush()->db->fetchAll($sql, array($this, 'push'));
81+
return $this;
82+
}
83+
84+
public function action() {}
85+
}

Plugin.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Typecho日志类、评论类等多功能工具箱!
4+
*
5+
* @package Typecho Kit
6+
* @author 冰剑
7+
* @version 2.0.0
8+
* @link http://www.binjoo.net
9+
*/
10+
class TeKit_Plugin implements Typecho_Plugin_Interface {
11+
public static function activate() {}
12+
public static function deactivate(){}
13+
public static function config(Typecho_Widget_Helper_Form $form){}
14+
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
15+
}

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## 插件说明 ##
2+
3+
- 版本: v2.0.0
4+
- 作者: [冰剑](https://github.com/binjoo)
5+
- 主页: <https://github.com/typecho-fans/plugins/tree/master/TeKit>
6+
7+
#### 日志类 TeKit_Contents
8+
###### 随机日志 Random
9+
|参数名称|是否必须|默认值|说明|
10+
|---|---|---|---|
11+
|number||10|显示数量|
12+
13+
###### 最多评论日志 MostCommented
14+
|参数名称|是否必须|默认值|说明|
15+
|---|---|---|---|
16+
|number||10|显示数量|
17+
18+
###### 历史上当天日志 HistoryToday
19+
|参数名称|是否必须|默认值|说明|
20+
|---|---|---|---|
21+
|number||10|显示数量|
22+
23+
###### 历史上当月日志 HistoryTomonth
24+
|参数名称|是否必须|默认值|说明|
25+
|---|---|---|---|
26+
|number||10|显示数量|
27+
28+
#### 评论类 TeKit_Comments
29+
###### 最多评论的人 MostCommentors
30+
|参数名称|是否必须|默认值|说明|
31+
|---|---|---|---|
32+
|days||NULL|多少天内|
33+
|number||10|显示数量|
34+
|ignore||true|不包含作者|
35+
36+
###### 最多沙发的人 MostSofaCommentors
37+
|参数名称|是否必须|默认值|说明|
38+
|---|---|---|---|
39+
|days||NULL|多少天内|
40+
|number||10|显示数量|
41+
|ignore||true|不包含作者|
42+
43+
###### 评论人评论数量 CommentorNumber
44+
|参数名称|是否必须|默认值|说明|
45+
|---|---|---|---|
46+
|author|||昵称|
47+
|mail|||Email|
48+
|days||30|多少天内|
49+
50+
###### 评论人评论 CommentorComments
51+
|参数名称|是否必须|默认值|说明|
52+
|---|---|---|---|
53+
|author|||昵称|
54+
|mail|||Email|
55+
|days||30|多少天内|
56+
57+
#### 其他类 TeKit_Other

0 commit comments

Comments
 (0)