forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
106 lines (95 loc) · 2.94 KB
/
Plugin.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* 小墙- 用最简单的方法墙掉垃圾评论
*
* @package AntiSpam
* @author Willin Kan
* @version 1.0.3
* @update: 2011.06.07
* @link http://kan.willin.org/typecho/
*/
class AntiSpam_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Typecho_Plugin::factory('Widget_Archive') ->beforeRender = array('AntiSpam_Plugin', 'field');
Typecho_Plugin::factory('Widget_Feedback')->comment = array('AntiSpam_Plugin', 'filter');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form)
{
$action = new Typecho_Widget_Helper_Form_Element_Radio(
'action', array(
0 => '直接挡掉.',
1 => '标记为 spam, 留在资料库检查是否误判.'
), 0,
'遇到 spam 的处理方法');
$form->addInput($action);
}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
/**
* 设栏位
*
* @access public
* @return void
*/
public static function field()
{
if (Typecho_Widget::widget('Widget_Archive')->is('single') && !Typecho_Widget::widget('Widget_User')->hasLogin()) {
ob_start(create_function('$input','return preg_replace("#textarea(.*?)name=([\"\'])text([\"\'])(.+)/textarea>#",
"textarea$1name=$2comment$3$4/textarea><textarea name=\"text\" cols=\"100%\" rows=\"4\" style=\"display:none\">spam</textarea>",$input);') );
}
}
/**
* 评论过滤器
*
* @access public
* @return void
*/
public static function filter($comment)
{
if (!Typecho_Widget::widget('Widget_User')->hasLogin()) {
$w = Typecho_Request::getInstance()->comment;
if (!empty($w) && $comment['text'] == 'spam') {
$comment['text'] = $w;
} else {
if (Typecho_Widget::widget('Widget_Options')->plugin('AntiSpam')->action) {
$comment['text'] = "[ 小墙判断这是 Spam! ]\n" . $comment['text'];
$comment['status'] = 'spam';
} else {
throw new Typecho_Exception('Spam Detected!');
}
}
}
return $comment;
}
}