forked from lincanbin/Carbon-Forum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.php
133 lines (124 loc) · 4.19 KB
/
json.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
<?php
include(__DIR__ . '/common.php');
SetStyle('api', 'API');
switch (Request('Get', 'action')) {
case 'get_notifications':
Auth(1);
header("Cache-Control: no-cache, must-revalidate");
set_time_limit(0);
//如果是自己的服务器,建议调大超时时间,然后把长连接时长调大,以节约服务器资源
$Config['PushConnectionTimeoutPeriod'] = intval((intval($Config['PushConnectionTimeoutPeriod']) < 22) ? 22 : $Config['PushConnectionTimeoutPeriod']);
while ((time() - $TimeStamp) < $Config['PushConnectionTimeoutPeriod']) {
if ($MCache) {
$CurUserInfo = $MCache->get(MemCachePrefix . 'UserInfo_' . $CurUserID);
if ($CurUserInfo) {
$CurNewMessage = $CurUserInfo['NewMessage'];
} else {
$TempUserInfo = $DB->row("SELECT * FROM " . $Prefix . "users WHERE ID = :UserID", array(
"UserID" => $CurUserID
));
$MCache->set(MemCachePrefix . 'UserInfo_' . $CurUserID, $TempUserInfo, 86400);
$CurNewMessage = $TempUserInfo['NewMessage'];
}
} else {
$CurNewMessage = $DB->single("SELECT NewMessage FROM " . $Prefix . "users WHERE ID = :UserID", array(
"UserID" => $CurUserID
));
}
if ($CurNewMessage > 0) {
break;
}
sleep(3);
}
echo json_encode(array(
'Status' => 1,
'NewMessage' => $CurNewMessage
));
break;
case 'get_tags':
Auth(1);
require(__DIR__ . "/includes/PHPAnalysis.class.php");
$str = Request('Post', 'Title') . "/r/n" . Request('Post', 'Content');
$do_fork = $do_unit = true;
$do_multi = $do_prop = $pri_dict = false;
//初始化类
PhpAnalysis::$loadInit = false;
$pa = new PhpAnalysis('utf-8', 'utf-8', $pri_dict);
//载入词典
$pa->LoadDict();
//执行分词
$pa->SetSource($str);
$pa->differMax = $do_multi;
$pa->unitWord = $do_unit;
$pa->StartAnalysis($do_fork);
$ResultString = $pa->GetFinallyResult('|', $do_prop);
$tags = array();
$tags['status'] = 0;
if ($ResultString) {
foreach (explode('|', $ResultString) as $key => $value) {
if ($value != '' && !is_numeric($value) && mb_strlen($value, "utf-8") >= 2) {
$SQLParameters[] = $value;
}
}
$TagsLists1 = $DB->column("SELECT Name FROM " . $Prefix . "tags Where Name IN (?)", $SQLParameters);
$TagsLists2 = $DB->column("SELECT Title FROM " . $Prefix . "dict Where Title IN (?) Group By Title", $SQLParameters);
//$TagsLists2 = array();
$TagsLists = array_merge($TagsLists1, array_diff($TagsLists2, $TagsLists1));
if ($TagsLists) {
$tags['status'] = 1;
rsort($TagsLists);
$tags['lists'] = $TagsLists;
}
}
echo json_encode($tags);
break;
case 'tag_autocomplete':
//Auth(1);
$Keyword = Request('Post', 'query');
$Response = array();
$Response['query'] = 'Unit';
$Result = $DB->column("SELECT Title FROM " . $Prefix . "dict WHERE Title LIKE :Keyword limit 10", array(
"Keyword" => $Keyword . "%"
));
if ($Result) {
foreach ($Result as $key => $val) {
$Response['suggestions'][] = array(
'value' => $val,
'data' => $val
);
}
} else {
$Response['suggestions'][] = '';
}
echo json_encode($Response);
break;
case 'user_exist':
$UserName = strtolower(Request('Post', 'UserName'));
$UserExist = $DB->single("SELECT ID FROM " . $Prefix . "users WHERE UserName = :UserName", array(
'UserName' => $UserName
));
echo json_encode(array(
'Status' => $UserExist ? 1 : 0
));
break;
case 'get_post':
$PostId = intval(Request('Post', 'PostId'));
$row = $DB->row("SELECT UserName, Content, TopicID FROM {$Prefix}posts WHERE ID = :PostId AND IsDel = 0", array(
'PostId' => $PostId
));
if ($CurUserRole < 4) {
// 对超级管理员以下的用户需要检查整个主题是否被删除了
$TopicID = $row['TopicID'];
$TopicRow = $DB->single("SELECT COUNT(*) FROM {$Prefix}topics WHERE ID = :TopicID AND IsDel = 0", array(
'TopicID' => $TopicID
));
if ($TopicRow < 1) {
$row = false;
}
}
echo json_encode($row);
break;
default:
# code...
break;
}