forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Action.php
162 lines (142 loc) · 5.99 KB
/
Action.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
class Links_Action extends Typecho_Widget implements Widget_Interface_Do
{
private $db;
private $options;
private $prefix;
public function insertLink()
{
/** 取出数据 */
if ($this->request->OEM == 'tf') {
$link = array(
'name' => 'Typecho Fans',
'url' => 'https://typecho-fans.github.io',
'email' => '[email protected]',
'image' => 'https://typecho-fans.github.io/text-logo.svg',
'description' => 'Typecho非官方粉丝群开源作品社区'
);
} else {
if (Links_Plugin::form('insert')->validate()) {
$this->response->goBack();
}
$link = $this->request->from('lid', 'email', 'image', 'url', 'state');
/** 过滤XSS */
$link['name'] = $this->request->filter('xss')->name;
$link['sort'] = $this->request->filter('xss')->sort;
$link['description'] = $this->request->filter('xss')->description;
$link['user'] = $this->request->filter('xss')->user;
}
$link['order'] = $this->db->fetchObject($this->db->select(array('MAX(order)' => 'maxOrder'))->from($this->prefix.'links'))->maxOrder + 1;
/** 插入数据 */
$link['lid'] = $this->db->query($this->db->insert($this->prefix.'links')->rows($link));
/** 设置高亮 */
$this->widget('Widget_Notice')->highlight('link-'.$link['lid']);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('友链%s已经被增加',
' <a href="'.$link['url'].'">'.$link['name'].'</a> '), null, 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('extending.php?panel=Links%2Fmanage-links.php', $this->options->adminUrl));
}
public function updateLink()
{
if (Links_Plugin::form('update')->validate()) {
$this->response->goBack();
}
/** 取出数据 */
$link = $this->request->from('lid', 'email', 'image', 'url', 'state');
/** 过滤XSS */
$link['name'] = $this->request->filter('xss')->name;
$link['sort'] = $this->request->filter('xss')->sort;
$link['description'] = $this->request->filter('xss')->description;
$link['user'] = $this->request->filter('xss')->user;
/** 更新数据 */
$this->db->query($this->db->update($this->prefix.'links')->rows($link)->where('lid = ?', $link['lid']));
/** 设置高亮 */
$this->widget('Widget_Notice')->highlight('link-'.$link['lid']);
/** 提示信息 */
$this->widget('Widget_Notice')->set(_t('友链%s已经被更新',
' <a href="'.$link['url'].'">'.$link['name'].'</a> '), null, 'success');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('extending.php?panel=Links%2Fmanage-links.php', $this->options->adminUrl));
}
public function deleteLink()
{
$lids = $this->request->filter('int')->getArray('lid');
$deleteCount = 0;
if ($lids && is_array($lids)) {
foreach ($lids as $lid) {
if ($this->db->query($this->db->delete($this->prefix.'links')->where('lid = ?', $lid))) {
$deleteCount ++;
}
}
}
/** 提示信息 */
$this->widget('Widget_Notice')->set($deleteCount > 0 ? _t('友链已经删除') : _t('没有友链被删除'), null,
$deleteCount > 0 ? 'success' : 'notice');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('extending.php?panel=Links%2Fmanage-links.php', $this->options->adminUrl));
}
public function enableLink()
{
$lids = $this->request->filter('int')->getArray('lid');
$enableCount = 0;
if ($lids && is_array($lids)) {
foreach ($lids as $lid) {
if ($this->db->query($this->db->update($this->prefix.'links')->rows(array('state' => '1'))->where('lid = ?', $lid))) {
$enableCount ++;
}
}
}
/** 提示信息 */
$this->widget('Widget_Notice')->set($enableCount > 0 ? _t('友链已经启用') : _t('没有友链被启用'), null,
$enableCount > 0 ? 'success' : 'notice');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('extending.php?panel=Links%2Fmanage-links.php', $this->options->adminUrl));
}
public function prohibitLink()
{
$lids = $this->request->filter('int')->getArray('lid');
$prohibitCount = 0;
if ($lids && is_array($lids)) {
foreach ($lids as $lid) {
if ($this->db->query($this->db->update($this->prefix.'links')->rows(array('state' => '0'))->where('lid = ?', $lid))) {
$prohibitCount ++;
}
}
}
/** 提示信息 */
$this->widget('Widget_Notice')->set($prohibitCount > 0 ? _t('友链已经禁用') : _t('没有友链被禁用'), null,
$prohibitCount > 0 ? 'success' : 'notice');
/** 转向原页 */
$this->response->redirect(Typecho_Common::url('extending.php?panel=Links%2Fmanage-links.php', $this->options->adminUrl));
}
public function sortLink()
{
$links = $this->request->filter('int')->getArray('lid');
if ($links && is_array($links)) {
foreach ($links as $sort => $lid) {
$this->db->query($this->db->update($this->prefix.'links')->rows(array('order' => $sort + 1))->where('lid = ?', $lid));
}
}
}
public function getMd5()
{
$this->response->throwJson(md5($this->request->email));
}
public function action()
{
Helper::security()->protect();
Typecho_Widget::widget('Widget_User')->pass('administrator');
$this->db = Typecho_Db::get();
$this->prefix = $this->db->getPrefix();
$this->options = Typecho_Widget::widget('Widget_Options');
$this->on($this->request->is('do=insert'))->insertLink();
$this->on($this->request->is('do=update'))->updateLink();
$this->on($this->request->is('do=delete'))->deleteLink();
$this->on($this->request->is('do=enable'))->enableLink();
$this->on($this->request->is('do=prohibit'))->prohibitLink();
$this->on($this->request->is('do=sort'))->sortLink();
$this->on($this->request->is('do=md5'))->getMd5();
$this->response->redirect($this->options->adminUrl);
}
}