module.php
3.05 KB
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
/**
* [WeEngine System] Copyright (c) 2014 WE7.CC
* WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
*/
defined('IN_IA') or exit('Access Denied');
class UserapiModule extends WeModule {
public $tablename = 'userapi_reply';
public function fieldsFormDisplay($rid = 0) {
global $_W;
if (!empty($rid)) {
$row = pdo_fetch("SELECT * FROM ".tablename($this->tablename)." WHERE rid = :rid ORDER BY `id` DESC", array(':rid' => $rid));
$row['type'] = 1; if (!strexists($row['apiurl'], 'http://') && !strexists($row['apiurl'], 'https://')) {
$row['apilocal'] = $row['apiurl'];
$row['type'] = 0; $row['apiurl'] = '';
}
} else {
$row = array(
'cachetime' => 0,
'type' => 1
);
}
$path = IA_ROOT . '/framework/builtin/userapi/api/';
if (is_dir($path)) {
$apis = array();
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$apis[] = $file;
}
}
}
}
include $this->template('form');
}
public function fieldsFormValidate($rid = 0) {
global $_GPC;
if (($_GPC['type'] && empty($_GPC['apiurl'])) || (empty($_GPC['type']) && empty($_GPC['apilocal']))) {
itoast('请填写接口地址!', '', '');
}
if ($_GPC['type'] && empty($_GPC['token'])) {
itoast('请填写Token值!', '', '');
}
return '';
}
public function fieldsFormSubmit($rid = 0) {
global $_GPC, $_W;
$reply = array(
'rid' => $rid,
'description' => $_GPC['description'],
'apiurl' => empty($_GPC['type']) ? $_GPC['apilocal'] : $_GPC['apiurl'],
'token' => $_GPC['wetoken'],
'default_text' => $_GPC['default-text'],
'cachetime' => intval($_GPC['cachetime']),
);
$is_exists = pdo_fetchcolumn('SELECT id FROM ' . tablename($this->tablename) . ' WHERE rid = :rid', array(':rid' => $rid));
if(!empty($is_exists)) {
if(pdo_update($this->tablename, $reply, array('rid' => $rid)) !== false) {
return true;
}
} else {
if(pdo_insert($this->tablename, $reply)) {
return true;
}
}
return false;
}
public function ruleDeleted($rid = 0) {
pdo_delete($this->tablename, array('rid' => $rid));
}
public function doSwitch() {
global $_W, $_GPC;
$m = array_merge($_W['modules']['userapi'], $_W['account']['modules']['userapi']);
$cfg = $m['config'];
if($_W['ispost']) {
$rids = explode(',', $_GPC['rids']);
if(is_array($rids)) {
$cfg = array();
foreach($rids as $rid) {
$cfg[intval($rid)] = true;
}
$this->saveSettings($cfg);
}
exit();
}
load()->model('reply');
$rs = reply_search("uniacid = 0 AND module = 'userapi' AND `status`=1");
$ds = array();
foreach($rs as $row) {
$reply = pdo_fetch('SELECT * FROM ' . tablename($this->tablename) . ' WHERE `rid`=:rid', array(':rid' => $row['id']));
$r = array();
$r['title'] = $row['name'];
$r['rid'] = $row['id'];
$r['description'] = $reply['description'];
$r['switch'] = $cfg[$r['rid']] ? ' checked="checked"' : '';
$ds[] = $r;
}
include $this->template('switch');
}
}