-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.php
108 lines (94 loc) · 3.52 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
107
108
<?php
/**
* 支持VAPTCHA的插件
*
* @package VAPTCHA
* @author Frank
* @version 1.0.0
* @link https://www.4leaf.top
*/
class VAPTCHA_Plugin implements Typecho_Plugin_Interface{
/* 激活插件方法 */
public static function activate(){
// 添加VAPTCHA所需css
Typecho_Plugin::factory('Widget_Archive')->header = array('VAPTCHA_Plugin', 'header');
// 添加VAPTCHA所需js
Typecho_Plugin::factory('Widget_Archive')->footer = array('VAPTCHA_Plugin', 'footer');
return _t('插件已启用');
}
/* 禁用插件方法 */
public static function deactivate(){
return _t('插件已禁用');
}
/* 插件配置方法 */
public static function config(Typecho_Widget_Helper_Form $form){
$vid = new Typecho_Widget_Helper_Form_Element_Text('vid', NULL, '****', _t('VID'), _t("验证单元id"));
$form->addInput($vid);
$button_id = new Typecho_Widget_Helper_Form_Element_Text('button_id', NULL, 'check', _t("按钮"), _t("请填入按钮ID,无需带#,验证前将禁止点击该按钮,验证成功后将允许点击该按钮"));
$form->addInput($button_id);
}
/* 个人用户的配置面板 */
public static function personalConfig(Typecho_Widget_Helper_Form $form){
}
/* 头部插入css */
public static function header(){
$VAPTCHA_style = "
<style>
.vaptcha-container {
width: 100%;
height: 36px;
line-height: 36px;
text-align: center;
}
.vaptcha-init-main {
display: table;
width: 100%;
height: 100%;
background-color: #EEEEEE;
}
.vaptcha-init-loading {
display: table-cell;
vertical-align: middle;
text-align: center
}
.vaptcha-init-loading>a {
display: inline-block;
width: 18px;
height: 18px;
border: none;
}
.vaptcha-init-loading>a img {
vertical-align: middle
}
.vaptcha-init-loading .vaptcha-text {
font-family: sans-serif;
font-size: 12px;
color: #CCCCCC;
vertical-align: middle
}
</style>
";
echo $VAPTCHA_style;
}
/* 尾部加入js */
public static function footer(){
$options = Typecho_Widget::widget('Widget_Options')->plugin('VAPTCHA');
$vaptcha_js = "
<script src=\"https://cdn.vaptcha.com/v2.js\"></script>
<script>
document.getElementById(\"".$options->button_id."\").setAttribute(\"disabled\", true);
vaptcha({
vid: '".$options->vid."', // 验证单元id
type: 'click', // 显示类型 点击式
container: '.vaptcha-container' // 按钮容器,可为Element 或者 selector
}).then(function (vaptchaObj) {
vaptchaObj.listen('pass', function() {
document.getElementById(\"".$options->button_id."\").removeAttribute(\"disabled\");
})
vaptchaObj.render()
})
</script>
";
echo $vaptcha_js;
}
}