-
Notifications
You must be signed in to change notification settings - Fork 3
/
interface.php
315 lines (282 loc) · 7.85 KB
/
interface.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
<?php
/**
* Custom interface
*
* Provide
*
* array $_IMC
* boolean $im_is_admin
* boolean $im_is_login
* object $imuser require when $im_is_login
* function webim_get_buddies()
* function webim_get_online_buddies()
* function webim_get_rooms()
* function webim_get_notifications()
* function webim_login()
*
*/
define( 'WEBIM_PRODUCT_NAME', 'discuzX' );
//discuzX1.5 will check url and report error when url content quote
$_SERVER['REQUEST_URI'] = "";
if ( !defined('IN_DISCUZ') ) {
require_once '../../class/class_core.php';
$discuz = & discuz_core::instance();
$discuz->init();
}
require_once DISCUZ_ROOT . './source/function/function_friend.php';
require_once DISCUZ_ROOT . './source/function/function_group.php';
//Find and insert data with utf8 client.
@DB::query( "SET NAMES utf8" );
@include_once 'config.php';
/**
*
* Provide the webim database config.
*
* $_IMC['dbuser'] MySQL database user
* $_IMC['dbpassword'] MySQL database password
* $_IMC['dbname'] MySQL database name
* $_IMC['dbhost'] MySQL database host
* $_IMC['dbtable_prefix'] MySQL database table prefix
* $_IMC['dbcharset'] MySQL database charset
*
*/
$_dbconfig = $_G['config']['db'][1];
$_IMC['dbuser'] = $_dbconfig['dbuser'];
$_IMC['dbpassword'] = $_dbconfig['dbpw'];
$_IMC['dbname'] = $_dbconfig['dbname'];
$_IMC['dbhost'] = $_dbconfig['dbhost'];
$_IMC['dbtable_prefix'] = $_dbconfig['tablepre'];
unset( $_dbconfig );
/**
* Init im user.
* -uid:
* -id:
* -nick:
* -pic_url:
* -show:
*
*/
//if( !defined('IN_DISCUZ') || !$_G['uid'] ) {
// exit('"Access Denied"');
//}
if ( $_G['uid'] ) {
webim_set_user();
$im_is_login = true;
} else {
$im_is_login = false;
}
$site_url = dirname ( dirname ( dirname( webim_urlpath() ) ) ) . "/";
$site_url = "";
function profile_url( $id ) {
global $site_url;
return $site_url . "home.php?mod=space&uid=" . $id;
}
function webim_get_menu () {
return array();
}
function webim_set_user( $is_utf8 = false ){
global $_G, $imuser;
$imuser->uid = $_G['uid'];
$id = $is_utf8 ? $_G['username'] : to_utf8( $_G['username'] );
$imuser->id = $id;
$imuser->nick = $id;
if( $_IMC['show_realname'] ) {
$data = DB::fetch_first("SELECT realname FROM ".DB::table('common_member_profile')." WHERE uid = $imuser->uid");
if( $data && $data['realname'] )
$imuser->nick = $data['realname'];
}
$imuser->pic_url = avatar($imuser->uid, 'small', true);
$imuser->show = webim_gp('show') ? webim_gp('show') : "available";
$imuser->url = profile_url( $imuser->uid );
complete_status( array( $imuser ) );
}
function webim_login( $username, $password, $question = "", $answer = "" ) {
global $imuser, $_G, $im_is_login;
$username = from_utf8( $username );
$_G['gp_cookietime'] = "";
// login and misc in X1, member in X1.5
$lib = libfile('function/login');
if( $lib ) require_once $lib;
$lib = libfile('function/misc');
if( $lib ) require_once $lib;
$lib = libfile('function/member');
if( $lib ) require_once $lib;
$result = userlogin( $username, $password, $question, $answer, $_G['setting']['autoidselect'] ? 'auto' : $_G['gp_loginfield']);
if($result['status'] > 0) {
setloginstatus($result['member'], $_G['gp_cookietime'] ? 2592000 : 0);
$im_is_login = true;
webim_set_user( true );
return true;
}
return false;
}
//Cache friend_groups;
$friend_groups = friend_group_list();
foreach($friend_groups as $k => $v){
$friend_groups[$k] = to_utf8($v);
}
/**
* Online buddy list.
*
*/
function webim_get_online_buddies(){
global $friend_groups, $imuser;
$list = array();
$query = DB::query("SELECT f.fuid uid, f.fusername username, p.realname name, f.gid
FROM ".DB::table('home_friend')." f, ".DB::table('common_session')." s, ".DB::table('common_member_profile')." p
WHERE f.uid='$imuser->uid' AND f.fuid = s.uid AND p.uid = s.uid
ORDER BY f.num DESC, f.dateline DESC");
while ($value = DB::fetch($query)){
$list[] = (object)array(
"uid" => $value['uid'],
"id" => $value['username'],
"nick" => nick($value),
"group" => $friend_groups[$value['gid']],
"url" => profile_url( $value['uid'] ),
"pic_url" => avatar($value['uid'], 'small', true),
);
}
complete_status( $list );
return $list;
}
/**
* Get buddy list from given ids
* $ids:
*
* Example:
* buddy('admin,webim,test');
*
*/
function webim_get_buddies( $names, $uids = null ){
global $friend_groups, $imuser;
$where_name = "";
$where_uid = "";
if(!$names and !$uids)return array();
if($names){
$names = "'".implode("','", explode(",", $names))."'";
$where_name = "m.username IN ($names)";
}
if($uids){
$where_uid = "m.uid IN ($uids)";
}
$where_sql = $where_name && $where_uid ? "($where_name OR $where_uid)" : ($where_name ? $where_name : $where_uid);
$list = array();
$query = DB::query("SELECT m.uid, m.username, p.realname name, f.gid FROM ".DB::table('common_member')." m
LEFT JOIN ".DB::table('home_friend')." f
ON f.fuid = m.uid AND f.uid = $imuser->uid
LEFT JOIN ".DB::table('common_member_profile')." p
ON m.uid = p.uid
WHERE m.uid <> $imuser->uid AND $where_sql");
while ( $value = DB::fetch( $query ) ){
$list[] = (object)array(
"uid" => $value['uid'],
"id" => $value['username'],
"nick" => nick($value),
"group" => $value['gid'] ? $friend_groups[$value['gid']] : "stranger",
"url" => profile_url( $value['uid'] ),
"pic_url" => avatar($value['uid'], 'small', true),
);
}
complete_status( $list );
return $list;
}
/**
* Get room list
* $ids: Get all imuser rooms if not given.
*
*/
function webim_get_rooms($ids=null){
global $imuser, $site_url;
if(!$ids){
$query = DB::query("SELECT fid FROM ".DB::table("forum_groupuser")." WHERE uid=$imuser->uid");
while ($value = DB::fetch($query)){
$ids[] = $value['fid'];
}
$ids = implode( ",", $ids );
}
$list = array();
if(!$ids){
return $list;
}
$where = "f.fid IN ($ids)";
$query = DB::query("SELECT f.fid, f.name, ff.icon, ff.membernum, ff.description
FROM ".DB::table('forum_forum')." f
LEFT JOIN ".DB::table("forum_forumfield")." ff ON ff.fid=f.fid
WHERE f.type='sub' AND f.status=3 AND $where");
while ($value = DB::fetch($query)){
$list[] = (object)array(
"fid" => $value['fid'],
"id" => $value['fid'],
"nick" => $value['name'],
"url" => $site_url . "forum.php?mod=group&fid=".$value['fid'],
"pic_url" => $site_url . get_groupimg($value['icon'], 'icon'),
"status" => $value['description'],
"count" => 0,
"all_count" => $value['membernum'],
"blocked" => false,
);
}
return $list;
}
function webim_get_notifications(){
return array();
}
/**
* Add status to member info.
*
* @param array $members the member list
* @return
*
*/
function complete_status( $members ) {
if(!empty($members)){
$num = count($members);
$ids = array();
$ob = array();
for($i = 0; $i < $num; $i++){
$m = $members[$i];
$id = $m->uid;
if ( $id ) {
$ids[] = $id;
$ob[$id] = $m;
}
}
$ids = implode(",", $ids);
$query = DB::query("SELECT uid, spacenote FROM ".DB::table('common_member_field_home')." WHERE uid IN ($ids)");
while($res = DB::fetch($query)) {
$ob[$res['uid']]->status = $res['spacenote'];
}
}
return $members;
}
function nick( $sp ) {
global $_IMC;
return (!$_IMC['show_realname']||empty($sp['name'])) ? $sp['username'] : $sp['name'];
}
function to_utf8( $s ) {
if( strtoupper( CHARSET ) == 'UTF-8' ) {
return $s;
} else {
if ( function_exists( 'iconv' ) ) {
return iconv( CHARSET, 'utf-8', $s );
} else {
require_once DISCUZ_ROOT . './source/class/class_chinese.php';
$chs = new Chinese( CHARSET, 'utf-8' );
return $chs->Convert( $s );
}
}
}
function from_utf8( $s ) {
if( strtoupper( CHARSET ) == 'UTF-8' ) {
return $s;
} else {
if ( function_exists( 'iconv' ) ) {
return iconv( 'utf-8', CHARSET, $s );
} else {
require_once DISCUZ_ROOT . './source/class/class_chinese.php';
$chs = new Chinese( 'utf-8', CHARSET );
return $chs->Convert( $s );
}
}
}
?>