forked from typecho-fans/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
245 lines (212 loc) · 9.19 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/**
* 批量更改文章分类、状态(公开|隐藏|私密)
*
* @package PostsCategoryChange
* @author Fuzqing
* @version 0.0.4
* @link https://huangweitong.com
*/
class PostsCategoryChange_Plugin implements Typecho_Plugin_Interface
{
/**
* 插件版本号
* @var string
*/
const _VERSION = '0.0.4';
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate()
{
Helper::addAction('imanage-posts', 'PostsCategoryChange_Action');
Typecho_Plugin::factory('admin/footer.php')->end = array(__CLASS__, 'render');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate()
{
Helper::removeAction('imanage-posts');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){}
/**
* 个人用户的配置面板
*
* @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 render()
{
$url = $_SERVER['REQUEST_URI'];
$filename = substr( $url , strrpos($url , '/')+1);
if (empty($filename) || strpos($filename,'manage-posts.php') === false) {
return;
}
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$options = Typecho_Widget::widget('Widget_Options');
$category_list = $db->fetchAll($db->select()->from($prefix.'metas')->where('type = ?', 'category'));
//批量更改文章分类接收的action地址
$makeChange_url = Typecho_Common::url('/index.php/action/imanage-posts?do=change-category', $options->siteUrl);
//批量更改文章分类接收的action地址
$changeStatus_url = Typecho_Common::url('/index.php/action/imanage-posts?do=change-status', $options->siteUrl);
$category_html = '<select name="icategory" id="category" style="width: 100%">';
$category_html .= '<option value="0">请选择一个分类</option>';
foreach ($category_list as $category) {
$category_html .= "<option value=\"{$category['mid']}\">{$category['name']}</option>";
}
$category_html .= '</select>';
$status_html = '<select name="status" id="status" style="width: 100%">';
$status_html .= '<option value="0">请选择文章状态</option>';
$status_html .= '<option value="1">公开</option>';
$status_html .= '<option value="2">隐藏</option>';
$status_html .= '<option value="3">私密</option>';
$status_html .= '</select>';
$script = <<<SCRIPT
<script src="//cdn.bootcss.com/layer/3.1.0/layer.js"></script>
<script>
$(document).ready(function(){
var html = '<li><a id="make-change" href="#">移动</a></li>';
html += '<li><a id="change-status" href="#">公开|隐藏|私密</a></li>';
$(".dropdown-menu").append(html);
$("#make-change").click(function() {
var params = $("form[name='manage_posts']").serialize();
if(!params) {
layer.msg('至少选择一篇文章', function(){});
return false;
} else {
mid = 0;
layer.open({
type: 1,
title:'移动到',
closeBtn: 0,
shadeClose: true,
btn: ['确定', '取消'],
content: '{$category_html}',
yes:function(index, layero) {
layer.close(index);
if(mid == undefined || mid == 0) {
layer.msg('请选择分类', function(){});
return false;
} else {
params = params + '&mid=' + mid;
var load_index = layer.load(2, {time: 10*1000});
$.post("{$makeChange_url}", params,function(data) {
layer.close(load_index);
if(data.code== -1) {
layer.msg(data.msg, function(){});
} else if(data.code == 1) {
layer.msg(data.msg, function(){
window.location.reload();
});
} else {
console.log(data);
}
},"json");
}
},
cancel: function(index, layero){
mid = 0;
layer.close(index)
return false;
}
});
$("#category").change(function(){
mid = $("#category").val();
});
}
});
$("#change-status").click(function() {
var params = $("form[name='manage_posts']").serialize();
if(!params) {
layer.msg('至少选择一篇文章', function(){});
return false;
} else {
status = 0;
layer.open({
type: 1,
title:'设置文章状态',
closeBtn: 0,
shadeClose: true,
btn: ['确定', '取消'],
content: '{$status_html}',
yes:function(index, layero) {
layer.close(index);
if(status == undefined || status == 0) {
layer.msg('请选择状态', function(){});
return false;
} else {
params = params + '&status=' + status;
var load_index = layer.load(2, {time: 10*1000});
$.post("{$changeStatus_url}", params,function(data) {
layer.close(load_index);
if(data.code== -1) {
layer.msg(data.msg, function(){});
} else if(data.code == 1) {
layer.msg(data.msg, function(){
window.location.reload();
});
} else {
console.log(data);
}
},"json");
}
},
cancel: function(index, layero){
status = 0;
layer.close(index)
return false;
}
});
$("#status").change(function(){
status = $("#status").val();
});
/**
var load_index = layer.load(2, {time: 10*1000});
$.post("{$changeStatus_url}", params,function(data) {
layer.close(load_index);
if(data.code== -1) {
layer.msg(data.msg, function(){});
} else if(data.code == 1) {
layer.msg(data.msg, function() {
window.location.reload();
});
} else {
console.log(data);
}
},"json");
*/
}
});
});
</script>
SCRIPT;
echo $script;
}
}