-
Notifications
You must be signed in to change notification settings - Fork 0
/
post.inc.php
72 lines (55 loc) · 2.33 KB
/
post.inc.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
<?php
include('./source/plugin/iltc_open/public.php');
if(isset($_G['gp_tid'])) $tid = $_G['gp_tid'];
else showError('Missing Parameter');
//TODO:Chech whether user is allowed to view this threads.
//Get Forum
$query = DB::query("SELECT fid, author, authorid, subject, dateline, views, replies FROM ".DB::table('forum_thread')." WHERE tid = $tid LIMIT 1");
$result['thread'] = DB::fetch($query);
if($result['thread'] == false) showError('No thread Found', 'error');
$result['thread']['author'] = iconv("GBK", "UTF-8", $result['thread']['author']);
$result['thread']['subject'] = iconv("GBK", "UTF-8", $result['thread']['subject']);
if(IS_GET){
$page = isset($_G['gp_page']) ? $_G['gp_page'] : 1;
$limit = isset($_G['gp_limit']) ? $_G['gp_limit'] : 20;
$sql = "SELECT pid, first, author, authorid, subject, dateline, message FROM "
.DB::table('forum_post')." WHERE tid = $tid AND invisible >= 0 ORDER BY pid LIMIT ".(($page - 1) * $limit).", $limit";
$query = DB::query($sql);
if(($temp = DB::fetch($query)) == false) showError('No Post Found', 'error');
do {
$temp['author'] = iconv("GBK", "UTF-8", $temp['author']);
$temp['subject'] = iconv("GBK", "UTF-8", $temp['subject']);
$temp['message'] = iconv("GBK", "UTF-8", $temp['message']);
$result['posts'][] = $temp;
} while($temp = DB::fetch($query));
//更新访问量
C::t('forum_thread')->update($tid, array('views' => $result['thread']['views']+1));
}else{
if(!isset($_G['gp_message'])) showError('Missing Parameter');
$query = DB::query("SELECT pid FROM ".DB::table('forum_post')." ORDER BY pid DESC LIMIT 1");
$temp = DB::fetch($query);
$pid = $temp['pid'] + 1;
C::t('forum_post')->insert('tid:'.$tid, array(
'pid' => $pid,
'tid' => $tid,
'fid' => $result['thread']['fid'],
'author' => $user_info['username'],
'authorid' => $user_info['uid'],
'dateline' => TIMESTAMP,
'message' => iconv("UTF-8", "GBK", $_G['gp_message']),
'useip' => $_G['clientip'],
'port' => $_G['remoteport'],
'position' => $result['thread']['replies'] + 2 //主楼占一个位置
));
//更新回帖信息
C::t('forum_thread')->update($tid, array(
'replies' => $result['thread']['replies']+1,
'lastpost' => TIMESTAMP,
'lastposter' => $user_info['username']
));
$result['newpost'] = array(
'pid' => $pid,
'message' => $_G['gp_message']
);
}
showResult($result, 'success');