-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin.class.php
399 lines (379 loc) · 17.7 KB
/
plugin.class.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<?php
if (!defined('IN_KKFRAME')) exit('Access Denied!');
class plugin_xxx_post extends Plugin {
public $description = '可以模仿客户端进行回帖(三倍经验yoooooooooooooo)';
public $modules = array(
array(
'id' => 'index',
'type' => 'page',
'title' => '客户端回帖',
'file' => 'index.php'
),
array(
'type' => 'cron',
'cron' => array(
'id' => 'xxx_post/c_daily',
'order' => '100'
)
),
array(
'type' => 'cron',
'cron' => array(
'id' => 'xxx_post/c_first',
'order' => '101'
)
),
array(
'type' => 'cron',
'cron' => array(
'id' => 'xxx_post/c_se',
'order' => '102'
)
),
array(
'type' => 'cron',
'cron' => array(
'id' => 'xxx_post/c_sxbk',
'order' => '103'
)
),
);
public $version = '0.4.1';
function checkCompatibility() {
if (version_compare(VERSION, '1.14.6.4', '<')) showmessage('签到助手版本过低,请升级');
}
function page_footer_js() {
echo '<script src="plugins/xxx_post/main.js"></script>';
}
function install() {
$query = DB::query('SHOW TABLES');
$tables = array();
while ($table = DB::fetch($query)) $tables[] = implode('', $table);
if (!in_array('xxx_post_posts', $tables)) {
runquery("
CREATE TABLE IF NOT EXISTS `xxx_post_posts` (
`sid` int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
`uid` int(10) unsigned NOT NULL,
`fid` int(10) unsigned NOT NULL,
`tid` bigint(12) unsigned NOT NULL,
`name` varchar(127) NOT NULL,
`unicode_name` varchar(512) NOT NULL,
`post_name` varchar(127) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `xxx_post_setting` (
`uid` int(10) unsigned NOT NULL PRIMARY KEY,
`client_type` tinyint(1) NOT NULL DEFAULT '5',
`frequency` tinyint(1) NOT NULL DEFAULT '2',
`delay` tinyint(2) NOT NULL DEFAULT '1',
`runtime` int(10) unsigned NOT NULL DEFAULT '0',
`runtimes` int(5) unsigned NOT NULL DEFAULT '6'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `xxx_post_content` (
`cid` int(10) unsigned AUTO_INCREMENT PRIMARY KEY,
`uid` int(10) unsigned NOT NULL,
`content` varchar(1024) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `xxx_post_log` (
`sid` int(10) unsigned NOT NULL,
`uid` int(10) unsigned NOT NULL,
`date` int(11) NOT NULL DEFAULT '0',
`status` tinyint(4) NOT NULL DEFAULT '0',
`retry` tinyint(3) unsigned NOT NULL DEFAULT '0',
UNIQUE KEY `sid` (`sid`,`date`),
KEY `uid` (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");
$this->saveSetting('sxbk', '0');
$this->saveSetting('se', '21');
$this->saveSetting('first_end', '15');
}
}
function uninstall() {
DB::query("DROP TABLE xxx_post_content,xxx_post_log,xxx_post_posts,xxx_post_setting");
showmessage("数据库删除成功。");
}
function on_upgrade($from_version) {
switch ($from_version) {
case '0':
case '0.2.2_13':
case '0.2.3':
case '0.3.0':
runquery("
UPDATE cron SET id='xxx_post/c_daily' WHERE id='xxx_post_daily';
UPDATE cron SET id='xxx_post/c_first' WHERE id='xxx_post';
UPDATE cron SET id='xxx_post/c_se' WHERE id='xxx_post_se';
UPDATE cron SET id='xxx_post/c_sxbk' WHERE id='xxx_post_sxbk';
alter table `xxx_post_posts` modify column `tid` bigint(12);
");
$this->saveSetting('sxbk', '0');
$this->saveSetting('se', '21');
$this->saveSetting('first_end', '15');
return '0.3.1';
case '0.3.1':
case '0.3.2':
case '0.3.3':
case '0.3.4':
runquery("alter table `xxx_post_posts` modify column `tid` bigint(12);");
return '0.3.5';
case '0.3.5':
case '0.3.6':
case '0.3.7':
case '0.3.8':
$this->saveSetting('min_delay', '0');
$this->saveSetting('max_delay', '15');
return '0.3.9';
case '0.3.9':
case '0.3.9.1':
case '0.4.0':
return '0.4.1';
default:
throw new Exception("Unknown plugin version: {$from_version}");
}
}
function on_config() {
if ($_POST) {
$sxbkset = (int)trim($_POST['sxbkset']);
$se_set = (int)trim($_POST['se_set']);
$first_end = (int)trim($_POST['first_end']);
$min_delay = (int)trim($_POST['min_delay']);
$max_delay = (int)trim($_POST['max_delay']);
$max_runtime = (int)$_POST['max_runtime'];
$min_delay = min(240, max(0, $min_delay));
$max_delay = min(240, max(0, $max_delay));
$max_runtime = max(6, min(999, $max_runtime));
if (!$sxbkset) $sxbkset = 0;
if ($se_set < 12) $se_set = 12;
else if ($se_set > 22) $se_set = 22;
if ($first_end < 1) $first_end = 1;
else if ($first_end > 22) $first_end = 22;
$this->saveSetting('sxbk', $sxbkset);
$this->saveSetting('se', $se_set);
$this->saveSetting('first_end', $first_end);
$this->saveSetting('min_delay', $min_delay);
$this->saveSetting('max_delay', $max_delay);
$this->saveSetting('max_runtime', $max_runtime);
showmessage("设置保存成功");
} else {
$sxbk = $this->getSetting('sxbk');
$se_set = $this->getSetting('se');
$first_end = $this->getSetting('first_end');
$min_delay = $this->getSetting('min_delay', 0);
$max_delay = $this->getSetting('max_delay', 15);
$max_runtime = $this->getSetting('max_runtime', 6);
$sxbk = $sxbk ? 'checked="cheched"' : '';
return <<<EOF
<P><label><input type="checkbox" name="sxbkset" value="1" $sxbk> 允许极限刷帖(此功能及其消耗服务器资源,而且会导致 sign_retry(重签) 任务无法执行,如果你是管理员,可以考虑禁用这个选项)</label></p><hr/>
<p>时间控制(24小时制):</p>
<p>在<input type="number" name="first_end" min="1" max="22" value="$first_end" style="outline:none;margin-left:4px;margin-right:4px"/>点之前结束第一次回帖(1 ~ 22)</p>
<p>在<input type="number" name="se_set" min="12" max="22" style="outline:none;margin-left:4px;margin-right:4px" value="$se_set"/>点之后开始第二次回帖(12 ~ 22)</p><hr/>
<p>延迟控制(分钟):</p>
<p>发出一贴后<b>最小</b>等待时间<input type="number" name="min_delay" min="0" max="240" style="outline:none;margin-left:4px;margin-right:4px" value="$min_delay"/>分钟(0 ~ 240)</p>
<p>发出一贴后<b>最大</b>等待时间<input type="number" name="max_delay" min="1" max="240" style="outline:none;margin-left:4px;margin-right:4px" value="$max_delay"/>分钟(1 ~ 240)</p><hr/>
<p>每位用户每次最多回<input type="number" name="max_runtime" min="1" max="999" style="outline:none;margin-left:4px;margin-right:4px" value="$max_runtime"/>个帖子(1 ~ 999)</p>
EOF;
}
}
function handleAction() {
global $uid;
if (!$uid) return;
switch ($_GET['action']) {
case 'delsid':
$_sid = intval($_GET['sid']);
DB::query("DELETE FROM xxx_post_posts WHERE sid='{$_sid}'");
$data['msg'] = "删除成功";
break;
case 'del-all-tid':
DB::query("DELETE FROM xxx_post_posts WHERE uid='{$uid}'");
$data['msg'] = "删除成功";
break;
case 'delcont':
$cid = intval($_GET['cid']);
DB::query("DELETE FROM xxx_post_content WHERE cid='{$cid}'");
$data['msg'] = "删除成功";
break;
case 'del-all-cont':
DB::query("DELETE FROM xxx_post_content WHERE uid='{$uid}'");
$data['msg'] = "删除成功";
break;
case 'set-content':
$contx = trim($_POST['post_content']);
if (empty($contx)) {
$data['msg'] = "设置失败,请输入字符串";
} else {
DB::insert('xxx_post_content', array(
'uid' => $uid,
'content' => $contx
));
$data['msg'] = "设置成功";
}
break;
case 'set-cont-plus':
$contplus = trim($_POST['x_p_contant']);
if (empty($contplus)) {
$data['msg'] = "设置失败,请输入字符串";
} else {
$cp_array = explode("\n", trim($contplus));
foreach ($cp_array as $contx) {
if (!trim($contx)) continue;
DB::insert('xxx_post_content', array(
'uid' => $uid,
'content' => $contx
));
}
$data['msg'] = "设置成功";
}
break;
case 'set-settings':
$client_type = (int)$_POST['x_p_client_type'];
$frequency = (int)$_POST['x_p_frequency'];
$runtimes = (int)$_POST['x_p_runtimes'];
$delay = (int)$_POST['x_p_delay'];
$min_delay = $this->getSetting('min_delay', 0);
$max_delay = $this->getSetting('max_delay', 15);
$max_runtime = $this->getSetting('max_runtime', 6);
$runtimes = min($max_runtime, max(1, $runtimes));
$delay = min($max_delay, max($min_delay, $delay));
DB::query("replace into xxx_post_setting (uid,client_type,frequency,delay,runtimes) values($uid,$client_type,$frequency,$delay,$runtimes)");
$data['msg'] = "设置成功";
break;
case 'post-settings':
$query = DB::query("SELECT * FROM xxx_post_posts WHERE uid='$uid'");
while ($result = DB::fetch($query)) {
$data['tiebas'][] = $result;
}
$query = DB::query("SELECT * FROM xxx_post_content WHERE uid='$uid'");
while ($result = DB::fetch($query)) {
$data['contents'][] = $result;
}
$data['count1'] = count($data['tiebas']);
$data['count2'] = count($data['contents']);
break;
case 'post-adv-settings':
$query = DB::query("SELECT * FROM xxx_post_setting WHERE uid='$uid'");
while ($result = DB::fetch($query)) {
$data['settings'] = $result;
}
if (!$data['settings']['client_type']) {
DB::query("insert into xxx_post_setting set uid=$uid");
$data['settings']['client_type'] = 5;
$data['settings']['frequency'] = 2;
$data['settings']['delay'] = 1;
$data['settings']['runtimes'] = 6;
}
break;
case 'add-tieba':
$tieba = trim($_POST['xxx_post_add_tieba']);
if (empty($tieba)) {
$data['msg'] = "添加失败,请输入贴吧名称!";
break;
}
$contents = _get_redirect_data('http://tieba.baidu.com/f?kw=' . urlencode($tieba) . '&fr=index');
$fid = 0;
preg_match('/"forum_id"\s?:\s?(?<fid>\d+)/', $contents, $fids);
$fid = !empty($fids) ? $fids['fid'] : 0;
if ($fid == 0) {
$data['msg'] = "添加失败,请检查贴吧名称并重试";
break;
}
preg_match('/"forum_name"\s?:\s?(?<fname>"\S+?")/', $contents, $fnames);
$fname = str_ireplace('"', '', $fnames['fname']);
$fname = $this->unicode2utf8($fname);
$unicode_name = urlencode($fname);
DB::insert('xxx_post_posts', array(
'uid' => $uid,
'fid' => $fid,
'tid' => 0,
'name' => $fname,
'unicode_name' => $unicode_name,
'post_name' => '随机'
));
$data['msg'] = "添加成功";
break;
case 'get-tid':
$tieurl = trim($_POST['xxx_post_tid']);
if (empty($tieurl)) {
$data['msg'] = "添加失败,请输入帖子地址!";
break;
}
preg_match('/tieba\.baidu\.com\/p\/(?<tid>\d+)/', $tieurl, $tids);
$tid = $tids['tid'];
$contents = _get_redirect_data("http://tieba.baidu.com/p/{$tid}");
$fid = 0;
preg_match('/"forum_id"\s?:\s?(?<fid>\d+)/', $contents, $fids);
$fid = !empty($fids) ? $fids['fid'] : 0;
if ($fid == 0) {
$data['msg'] = "添加失败,请检查帖子地址并重试";
$data['msgx'] = 0;
break;
}
preg_match('/fname=\"(.+?)\"/', $contents, $fnames);
$unicode_name = urlencode($fnames[1]);
$fname = $fnames[1];
preg_match('/title:\s?"(.*?)\"/', $contents, $post_names);
$post_name = $post_names[1];
DB::insert('xxx_post_posts', array(
'uid' => $uid,
'fid' => $fid,
'tid' => $tid,
'name' => $fname,
'unicode_name' => $unicode_name,
'post_name' => $post_name
));
$data['msg'] = "添加成功";
break;
case 'test_post':
include_once ('plugins/xxx_post/core.php');
$tiezi_count = DB::result_first("SELECT COUNT(*) FROM xxx_post_posts WHERE uid='$uid'");
$tiezi_offset = mt_rand(1, $tiezi_count) - 1;
$tiezi = DB::fetch_first("SELECT * FROM xxx_post_posts WHERE uid='$uid' limit $tiezi_offset,1");
if (!$tiezi) showmessage('没有添加帖子,请先添加!');
$x_content_count = DB::result_first("SELECT COUNT(*) FROM xxx_post_content WHERE uid='$uid'");
if ($x_content_count > 0) {
$x_content_offset = mt_rand(1, $x_content_count) - 1;
$x_content = DB::result_first("SELECT content FROM xxx_post_content WHERE uid='$uid' limit $x_content_offset,1");
} else {
$x_content = '';
}
list($status, $result) = client_rppost($uid, $tiezi, $x_content);
if ($status == 2) {
$status_str = '发帖成功';
$str = '';
} else {
$status_str = '发帖失败';
$str = "<p>错误代码:{$status}</p>";
}
showmessage("<p>测试帖子:【{$tiezi['name']}吧】{$tiezi['post_name']}</p><p>测试结果:{$status_str}</p>{$str}<p>详细信息:{$result}</p>");
break;
case 'post-log':
$date = date('Ymd');
$data['date'] = date('Y-m-d');
case 'post-history':
if ($_GET['action'] == 'post-history') {
$date = (int)$_GET['date'];
$data['date'] = substr($date, 0, 4) . '-' . substr($date, 4, 2) . '-' . substr($date, 6, 2);
}
$data['log'] = array();
$query = DB::query("SELECT * FROM xxx_post_log l LEFT JOIN xxx_post_posts t ON t.sid=l.sid WHERE l.uid='$uid' AND l.date='$date'");
while ($result = DB::fetch($query)) {
if (!$result['sid']) continue;
$data['log'][] = $result;
}
$data['count'] = count($data['log']);
$data['before_date'] = DB::result_first("SELECT date FROM xxx_post_log WHERE uid='{$uid}' AND date<'{$date}' ORDER BY date DESC LIMIT 0,1");
$data['after_date'] = DB::result_first("SELECT date FROM xxx_post_log WHERE uid='{$uid}' AND date>'{$date}' ORDER BY date ASC LIMIT 0,1");
break;
}
echo json_encode($data);
}
function unicode2utf8($str) {
if (!$str) return $str;
$decode = json_decode($str);
if ($decode) return $decode;
$str = '["' . $str . '"]';
$decode = json_decode($str);
if (count($decode) == 1) {
return $decode[0];
}
return $str;
}
}