Skip to content

Commit f407a91

Browse files
committed
add openapi plugin and fixed some bugs
1 parent e92de3a commit f407a91

19 files changed

+546
-7
lines changed

control/common_control.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ protected function check_access($forum, $action) {
554554
// 检查是否登录
555555
public function check_login() {
556556
if(empty($this->_user['uid'])) {
557-
$this->message('您还没有登录,请先登录。', -1); // .print_r($_COOKIE, 1)
557+
$this->message('您还没有登录,请先登录。', 0); // .print_r($_COOKIE, 1)
558558
}
559559
}
560560

control/index_control.class.php

+34
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,40 @@ public function article() {
159159
public function blog() {
160160

161161
}
162+
public function on_forumlist() {
163+
$arr = array();
164+
foreach($this->conf['forumarr'] as $fid => $name) {
165+
$forum = $this->mcache->read('forum', $fid);
166+
$ismod = $this->is_mod($forum, $this->_user);
167+
$arradd1 = !empty($forum['typecates'][1]) && (empty($forum['typecates_mod'][1]) || $forum['typecates_mod'][1] && $ismod) ? array('0'=>$forum['typecates'][1].'') : array();
168+
$arradd2 = !empty($forum['typecates'][2]) && (empty($forum['typecates_mod'][2]) || $forum['typecates_mod'][2] && $ismod) ? array('0'=>$forum['typecates'][2].'') : array();
169+
$arradd3 = !empty($forum['typecates'][3]) && (empty($forum['typecates_mod'][3]) || $forum['typecates_mod'][3] && $ismod) ? array('0'=>$forum['typecates'][3].'') : array();
170+
$arradd4 = !empty($forum['typecates'][4]) && (empty($forum['typecates_mod'][4]) || $forum['typecates_mod'][4] && $ismod) ? array('0'=>$forum['typecates'][4].'') : array();
171+
$typearr1 = empty($forum['types'][1]) || empty($arradd1) ? array() : $arradd1 + (array)$forum['types'][1];
172+
$typearr2 = empty($forum['types'][2]) || empty($arradd2) ? array() : $arradd2 + (array)$forum['types'][2];
173+
$typearr3 = empty($forum['types'][3]) || empty($arradd3) ? array() : $arradd3 + (array)$forum['types'][3];
174+
$typearr4 = empty($forum['types'][4]) || empty($arradd4) ? array() : $arradd4 + (array)$forum['types'][4];
175+
$ta = array('fid' => $fid, 'name' => $name, 'types' => array());
176+
$ta['types']['typeid1'] = array();
177+
foreach($typearr1 as $k => $v) {
178+
$ta['types']['typeid1'][] = array('id'=>$k, 'name' => $v);
179+
}
180+
$ta['types']['typeid2'] = array();
181+
foreach($typearr2 as $k => $v) {
182+
$ta['types']['typeid2'][] = array('id'=>$k, 'name' => $v);
183+
}
184+
$ta['types']['typeid3'] = array();
185+
foreach($typearr3 as $k => $v) {
186+
$ta['types']['typeid3'][] = array('id'=>$k, 'name' => $v);
187+
}
188+
$ta['types']['typeid4'] = array();
189+
foreach($typearr4 as $k => $v) {
190+
$ta['types']['typeid4'][] = array('id'=>$k, 'name' => $v);
191+
}
192+
$arr[] = $ta;
193+
}
194+
$this->message($arr);
195+
}
162196

163197
private function get_toplist($forum = array()) {
164198
$fidtids = array();

control/post_control.class.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function on_thread() {
152152

153153
$tid = $thread['tid'] = $this->thread->create($thread);
154154
if(!$thread['tid']) {
155-
$this->message('发帖过程中保存数据错误,请联系管理员。');
155+
$this->message('发帖过程中保存数据错误,请联系管理员。', 0);
156156
}
157157

158158
// hook post_thread_create_after.php
@@ -270,7 +270,7 @@ public function on_post() {
270270

271271
// 帖子回复数不能超过 10000
272272
if($thread['posts'] > 10000) {
273-
$this->message('该帖子回复数已经达到10000,不能再回复了,再起话题吧!');
273+
$this->message('该帖子回复数已经达到10000,不能再回复了,再起话题吧!', 0);
274274
}
275275

276276
// 版块权限检查
@@ -611,7 +611,7 @@ public function on_delete() {
611611

612612
// 检查是否为 post 提交
613613
if(!core::gpc('formhash', 'P')) {
614-
$this->message('非法请求!');
614+
$this->message('非法请求!', 0);
615615
}
616616

617617
$this->check_login();

control/user_control.class.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function on_login() {
3939

4040
if(empty($email)) {
4141
$error['email'] = '请填写用户名或Email';
42-
$this->message($error);
42+
$this->message($error['email'], 0);
4343
}
4444

4545
// hook user_login_check_before.php
@@ -49,7 +49,7 @@ public function on_login() {
4949
if(empty($userdb)) {
5050
$error['email'] = '用户名/Email 不存在';
5151
log::write('EMAIL不存在:'.$email, 'login.php');
52-
$this->message($error);
52+
$this->message($error['email'], 0);
5353
}
5454
}
5555
$uid = $userdb['uid'];
@@ -58,7 +58,7 @@ public function on_login() {
5858
$error['password'] = '密码错误!';
5959
$log_password = '******'.substr($password, 6);
6060
log::write("密码错误:$email - $log_password", 'login.php');
61-
$this->message($error);
61+
$this->message($error['password'], 0);
6262
}
6363

6464
// hook user_login_check_after.php
@@ -130,6 +130,9 @@ public function on_create() {
130130

131131
// check 数据格式
132132
$error['email'] = $this->user->check_email($email);
133+
if(array_filter($error)) {
134+
$this->message($error['email'], 0);
135+
}
133136
$error['email_exists'] = $this->user->check_email_exists($email);
134137

135138
// 如果email存在
@@ -147,6 +150,9 @@ public function on_create() {
147150
$error['password'] = $this->user->check_password($password);
148151
$error['password2'] = $this->user->check_password2($password, $password2);
149152

153+
if(array_filter($error)) {
154+
$this->message(implode(' | ',$error), 0);
155+
}
150156
$groupid = $this->conf['reg_email_on'] ? 6 : 11;
151157
$salt = $this->user->randString(9);
152158
$user = array(
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
protected function init_app() {
2+
if($this->appkey) {
3+
$app = $this->open_app->get_app_by_appkey($this->appkey);
4+
if(empty($app)) {
5+
$this->appkey = NULL;
6+
$this->seckey = NULL;
7+
}
8+
$this->app = $app;
9+
}
10+
}
11+
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public $appkey= NULL;
2+
public $seckey = NULL;
3+
public $app = array();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
if($this->format == "json") $_GET["ajax"] = 1;
2+
$this->appkey = core::gpc("appkey","R");
3+
$this->seckey = core::gpc("seckey","R");
4+
if(core::gpc("auth","R")) {
5+
$auth = core::gpc("auth","R");
6+
$_GET[$this->conf['cookie_pre'] . 'auth'] = $auth;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$this->init_app();

plugin/openapi/conf.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
return array (
4+
'name' => '开放API', // 插件名
5+
'brief' => '开放API',
6+
'version' => '1.0.0', // 插件版本
7+
'bbs_version' => '1.1.0', // 插件支持的 Xiuno BBS 版本
8+
'cateid' => 4,
9+
);
10+
?>

plugin/openapi/form_submit_after.php

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if($this->seckey && isset($this->app['seckey'])) {
2+
return $this->seckey == $this->app['seckey'];
3+
}

plugin/openapi/install.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
!defined('FRAMEWORK_PATH') && exit('FRAMEWORK_PATH not defined.');
3+
$db_table = array(
4+
'open_app'=>array (
5+
array('aid', 'int(10)'),
6+
array('uid', 'int(10)'),
7+
array('username', 'varchar(16)'),
8+
array('created', 'int(10)'),
9+
array('modified', 'int(10)'),
10+
array('name', 'varchar(16)'),
11+
array('screenname', 'varchar(16)'),
12+
array('type', 'varchar(16)'),
13+
array('description', 'varchar(200)'),
14+
array('appkey', 'varchar(200)'),
15+
array('seckey', 'varchar(200)'),
16+
array('verify', 'tinyint(1)')
17+
),
18+
'open_user'=>array (
19+
array('uid', 'int(10)'),
20+
array('username', 'varchar(16)'),
21+
array('subject', 'varchar(100)'),
22+
array('content', 'longtext')
23+
)
24+
);
25+
26+
$db_index = array(
27+
'open_app'=>array(
28+
array('aid'=>1),
29+
array('uid'=>1),
30+
array('name'=>1),
31+
array('screenname'=>1),
32+
array('type'=>1),
33+
array('appkey'=>1),
34+
array('seckey'=>1)
35+
),
36+
'open_user'=>array(array('uid'=>1))
37+
);
38+
39+
$db = $this->user->db;
40+
foreach($db_table as $table=>$cols) {
41+
$db->table_drop($table);
42+
$db->table_create($table, $cols);
43+
}
44+
45+
//
46+
foreach($db_index as $table=>$indexes) {
47+
foreach($indexes as $index) {
48+
$db->index_create($table, $index);
49+
}
50+
}

plugin/openapi/open_app.class.php

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) zdsr.com
5+
*/
6+
7+
class open_app extends base_model{
8+
9+
function __construct(&$conf) {
10+
parent::__construct($conf);
11+
$this->table = 'open_app';
12+
$this->primarykey = array('aid');
13+
$this->maxcol = 'aid';
14+
15+
// hook open_app_construct_end.php
16+
}
17+
18+
public function get_app_by_appkey($appkey) {
19+
// 根据非主键取数据
20+
$applist = $this->index_fetch( array('appkey'=>$appkey), array(), 0, 1);
21+
return $applist ? array_pop($applist) : array();
22+
}
23+
24+
public function get_applist($start = 0,$limit = 100) {
25+
$applist = $this->index_fetch(array(), array('created'=>-1), $start, $limit);
26+
return $applist;
27+
}
28+
29+
// 用来显示给用户
30+
public function format(&$app) {
31+
if(empty($app)) return;
32+
$app['created_fmt'] = misc::humandate($app['created']);
33+
$app['modified_fmt'] = misc::humandate($app['modified']);
34+
}
35+
36+
public function check_name_exists($name) {
37+
$app = $this->index_fetch(array('name'=>$name),array(),0,1);
38+
return $app ? '该应用名称已存在。' : '';
39+
}
40+
41+
public function check_screenname_exists($screenname) {
42+
$app = $this->index_fetch(array('screenname'=>$screenname),array(),0,1);
43+
return $app ? '该显示名称已存在。' : '';
44+
}
45+
46+
public function generate_appkey() {
47+
return time();
48+
}
49+
50+
public function generate_seckey() {
51+
return md5(rand(100,999) . time());
52+
}
53+
54+
public function html_safe($doc) {
55+
return xn_html_safe::filter($doc);
56+
}
57+
58+
// hook open_app_model_end.php
59+
}
60+
?>

plugin/openapi/open_control.class.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/*
4+
* Copyright (C) zdsr.com
5+
*/
6+
7+
!defined('FRAMEWORK_PATH') && exit('FRAMEWORK_PATH not defined.');
8+
9+
include BBS_PATH.'control/common_control.class.php';
10+
11+
class open_control extends common_control {
12+
13+
function __construct(&$conf) {
14+
parent::__construct($conf);
15+
$this->_title[] = ($this->conf['seo_title'] ? $this->conf['seo_title'] : $this->conf['app_name']) . '开放平台';
16+
//$this->_seo_keywords = $this->conf['seo_keywords'];
17+
//$this->_seo_description = $this->conf['seo_description'];
18+
}
19+
20+
public function on_index() {
21+
$applist = $this->open_app->get_applist();
22+
foreach($applist as &$app) {
23+
$this->open_app->format($app);
24+
}
25+
$this->format == "json" && $this->json($applist);
26+
$this->view->assign("applist",$applist);
27+
$this->view->display("open_index.htm");
28+
}
29+
30+
public function on_view() {
31+
$aid = core::gpc("aid");
32+
$app = $this->open_app->read($aid);
33+
$this->format == "json" && $this->json($app);
34+
$this->view->assign("app",$app);
35+
$this->view->display("open_view.htm");
36+
}
37+
38+
public function on_create() {
39+
$this->check_login();
40+
if($this->form_submit()) {
41+
$error = array();
42+
$name = core::gpc("name","P");
43+
$screenname = core::gpc("screenname","P");
44+
$error['name'] = $this->open_app->check_name_exists($name);
45+
$error['screenname'] = $this->open_app->check_screenname_exists($screenname);
46+
if(array_filter($error)) $this->message($error);
47+
$description = core::gpc("description","P");
48+
$type = core::gpc("type","P");
49+
$created = time();
50+
$modified = time();
51+
$appkey = $this->open_app->generate_appkey();
52+
$seckey = $this->open_app->generate_seckey();
53+
$arr = array(
54+
'uid'=>$this->_user['uid'],
55+
'username'=>$this->_user['username'],
56+
'created'=>$created,
57+
'modified'=>$modified,
58+
'name'=>$name,
59+
'screenname'=>$screenname,
60+
'type'=>$type,
61+
'description'=>$description,
62+
'appkey'=>$appkey,
63+
'seckey'=>$seckey,
64+
'verify'=>0
65+
);
66+
$aid = $this->open_app->create($arr);
67+
$this->message("应用创建完成。",1,"?open-index.htm");
68+
}
69+
array_unshift($this->_title,'创建新应用');
70+
$this->view->display("open_create.htm");
71+
}
72+
//end class
73+
}
74+
?>

plugin/openapi/open_create.htm

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!--{include header.htm}-->
2+
3+
<div class="width">
4+
<div class="div">
5+
<div class="header"><span class="icon"></span>创建新应用 > $conf[app_name]开放平台</div>
6+
<div class="body">
7+
<div style="margin-top: 8px; line-height: 12px; margin-bottom: 4px;">
8+
<form action="?open-create.htm" method="post" id="create_app">
9+
<input type="hidden" name="FORM_HASH" value="{FORM_HASH}" />
10+
<p><label for="name">应用名称:</label>
11+
<input type="text" id="name" name="name" />
12+
<span>应用名称,建议使用字母</span>
13+
</p>
14+
<p><label for="screenname">显示名称:</label>
15+
<input type="text" id="screenname" name="screenname" />
16+
<span>用于显示给用户</span>
17+
</p>
18+
<p><label for="type"> 应用类型:</label>
19+
<select id="type" name="type">
20+
<option value="exe">独立exe执行程序</option>
21+
<option value="dll">dll调用</option>
22+
<option value="url">url网页应用</option>
23+
</select>
24+
</p>
25+
<p><label for="description">应用描述:</label>
26+
<input type="text" id="description" name="description" />
27+
</p>
28+
<p><button type="submit">提交申请</button></p>
29+
</form>
30+
</div>
31+
</div>
32+
<div class="footer"></div>
33+
</div>
34+
</div>
35+
36+
<!--{include footer.htm}-->
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)